DMD 0.165 release

Tom S h3r3tic at remove.mat.uni.torun.pl
Sun Aug 20 23:07:39 PDT 2006


Tom S wrote:
> Walter Bright wrote:
>> I was going to call this 1.0 RC1, but I just could not resist adding 
>> the lazy expression evaluation. This adds one of the big capabilities 
>> of common lisp.
>>
>> http://www.digitalmars.com/d/changelog.html
> 
> Simply WOW !
> I can't wait to use the feature. Btw, I think there is a bug in the 
> Enforce example... IMO It should look more like in this test case:
> 
> 
> 
> import std.stdio;
> 
> 
> class Spam {
>     void ham() {
>         writefln("ham() called !");
>     }
> }
> 
> 
> T Enforce(T)(T delegate() p, char[] msg)
> {
>     writefln("entering Enforce()");
>     auto res = p();
>     if (!res)
>     throw new Exception(msg);
>     return res;
> }
> 
> 
> Spam foo(int a, int b) {
>     writefln("entering foo()");
>     if (a == b) return new Spam;
>     else return null;
> }
> 
> 
> void main() {
>     Enforce(foo(1, 1), "omigosh !").ham();
>     Enforce(foo(1, 2), "omigosh !").ham();
> }

Ooops maybe I'm too sleepy. You probably meant Enforce to look like this:


T Enforce(T)(T p, char[] delegate() msg)
{
     if (!p)
	throw new Exception(msg());
     return p;
}


That would make more sense, as the message is lazily evaluated then...



More information about the Digitalmars-d-announce mailing list