I hope I didn't miss anything; I copied it from the book.<br><br>import std.stdio, std.exception;<br><br>interface Stat{<br> void accumulate(double x);<br> void postprocess();<br> double result();<br>}<br><br>
class Min : Stat{<br> private double min = double.max;<br> void accumulate(double x){<br> if( x < min ){<br> min = x;<br> }<br> }<br><br> void postprocess(){ }<br> double result(){<br>
return min;<br> }<br>}<br><br>void main(string[] args){<br><br> Stat[] stats;<br> foreach(arg; args[1 .. $]){<br> auto newStat = cast(Stat) Object.factory("stats." ~ arg);<br> enforce(newStat, "Invalid statistics function: " ~ arg);<br>
stats ~= newStat;<br> }<br> for(double x; stdin.readf(" %s ", &x) == 1; ){<br> foreach(s; stats){<br> s.accumulate(x);<br> }<br> }<br> foreach(s; stats){<br>
s.postprocess();<br> writeln(s.result());<br> }<br>}<br><br><br><div class="gmail_quote">On Thu, Dec 23, 2010 at 6:04 PM, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org">SeeWebsiteForEmail@erdani.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">On 12/23/10 5:50 PM, Caligo wrote:<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
<br>
<br>
On Thu, Dec 23, 2010 at 5:38 PM, Andrej Mitrovic<br></div><div class="im">
<<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.com</a> <mailto:<a href="mailto:andrej.mitrovich@gmail.com" target="_blank">andrej.mitrovich@gmail.com</a>>> wrote:<br>
<br>
On 12/24/10, Caligo <<a href="mailto:iteronvexor@gmail.com" target="_blank">iteronvexor@gmail.com</a><br></div><div><div></div><div class="h5">
<mailto:<a href="mailto:iteronvexor@gmail.com" target="_blank">iteronvexor@gmail.com</a>>> wrote:<br>
> You got me excited, so I decided to give GDC another try. I<br>
cloned the<br>
> repo, and using GCC 4.4.5, it compiled without errors.<br>
> I started following the examples in TDPL, but the Stat program on<br>
page 22<br>
> gives the following errors:<br>
><br>
> t1.d:33: Error: void has no value<br>
> t1.d:33: Error: incompatible types for ((readf(" %s ",& x)) ==<br>
(1)): 'void'<br>
> and 'int'<br>
><br>
> is there a typo in the code, or is this some kind of bug in GDC?<br>
<br>
Use stdin.readf:<br>
<br>
import std.exception, std.stdio;<br>
void main(string[] args) {<br>
for (double x; stdin.readf(" %s ", &x) == 1; ) {<br>
}<br>
}<br>
<br>
The TDPL errata is here btw, that bug is listed:<br>
<a href="http://erdani.com/tdpl/errata/index.php?title=Main_Page" target="_blank">http://erdani.com/tdpl/errata/index.php?title=Main_Page</a><br>
<br>
<br>
<br></div></div>
great, that fixed the problem. I was actually trying to find the errata<div class="im"><br>
too, so thanks for that.<br>
<br>
The example compiles but it throws an exception:<br>
<br>
>> echo 3 4 6.6 7.7 33.4 | ./t1 Min Max Average<br>
object.Exception@3030object.Exception@30<br>
</div></blockquote>
<br>
Would you mind posting the entire code? Thanks.<br><font color="#888888">
<br>
Andrei<br>
</font></blockquote></div><br>