August 21, 2006
Tom S wrote:
> The supplied example:
> 
> void foo()
> {
>     int v = 2;
>     cond
>     (
>     scase(v == 1, writefln("it is 1")),
>     scase(v == 2, writefln("it is 2")),
>     scase(v == 3, writefln("it is 3")),
>     scase(true,   writefln("it is the default"))
>     );
> }
> 
> Gives errors: 'voids have no value'. It works when writefln is changed to printf, as it returns an int... It would be cool if voids were also allowed to be lazy.

That's what I get for changing the code at the last minute. :-(
August 21, 2006
Unknown W. Brackets wrote:
> Hmmm... what does the last example about Enforce have to do with lazy evaluation?
> 
> It seems like a nice idea, etc., but I can actually run it already without upgrading to 0.165.....?
> 
> Does really sound nice, though :).


See my second reply to this thread... the point is that 'msg' should be char[] delegate(). Then you can supply an expression to Enforce, e.g.
Enforce(a == b, toString(a) ~ " != " ~ toString(b));
and it will only be evaluated in the case when a != b, thus making your code faster.


--
Tomasz Stachowiak
August 21, 2006
Unknown W. Brackets wrote:
> Hmmm... what does the last example about Enforce have to do with lazy evaluation?

The expression shouldn't be evaluated if the error happens.

> It seems like a nice idea, etc., but I can actually run it already without upgrading to 0.165.....?

Yes, if you put the delegate part as { return exp; } instead of just exp.
August 21, 2006
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

This is just beautiful, thanks! thanks! thanks!
August 21, 2006
Walter Bright wrote:
> Tom S wrote:
>> The supplied example:
>>
>> void foo()
>> {
>>     int v = 2;
>>     cond
>>     (
>>     scase(v == 1, writefln("it is 1")),
>>     scase(v == 2, writefln("it is 2")),
>>     scase(v == 3, writefln("it is 3")),
>>     scase(true,   writefln("it is the default"))
>>     );
>> }
>>
>> Gives errors: 'voids have no value'. It works when writefln is changed to printf, as it returns an int... It would be cool if voids were also allowed to be lazy.
> 
> That's what I get for changing the code at the last minute. :-(

:)

I get voids have no value for the dotimes example on line:
dotimes(10, writef(x++));

August 21, 2006
Ivan Senji wrote:
> Walter Bright wrote:
>> Tom S wrote:
>>> The supplied example:
>>>
>>> void foo()
>>> {
>>>     int v = 2;
>>>     cond
>>>     (
>>>     scase(v == 1, writefln("it is 1")),
>>>     scase(v == 2, writefln("it is 2")),
>>>     scase(v == 3, writefln("it is 3")),
>>>     scase(true,   writefln("it is the default"))
>>>     );
>>> }
>>>
>>> Gives errors: 'voids have no value'. It works when writefln is changed to printf, as it returns an int... It would be cool if voids were also allowed to be lazy.
>>
>> That's what I get for changing the code at the last minute. :-(
> 
> :)
> 
> I get voids have no value for the dotimes example on line:
> dotimes(10, writef(x++));
> 

Hmmm, In trying to get the example to work i tried
dotimes(10, (writef(x++),0));

To turn the expression to something other than void but
now it prints:
[int]0[int]1[int]2[int]3[int]4[int]5[int]6[int]7[int]8[int]9
and I can't understand why is this happening?

August 21, 2006
On Mon, 21 Aug 2006 07:32:37 +0300, Walter Bright <newshound@digitalmars.com> 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


I was very impressed by D... Now I am very much more! :)

I hope D will have a great impact on the programming language field. At least D deserves it!

Actually I will not be surprised to see if D will be THE programming language someday... It'll take time and work, sure. (Companies will act a lot slower, of course, than individuals.) But hey, maybe after 5-7 years... :)
August 21, 2006
Ivan Senji wrote:
> Ivan Senji wrote:
>> Walter Bright wrote:
>>> Tom S wrote:
>>>> The supplied example:
>>>>
>>>> void foo()
>>>> {
>>>>     int v = 2;
>>>>     cond
>>>>     (
>>>>     scase(v == 1, writefln("it is 1")),
>>>>     scase(v == 2, writefln("it is 2")),
>>>>     scase(v == 3, writefln("it is 3")),
>>>>     scase(true,   writefln("it is the default"))
>>>>     );
>>>> }
>>>>
>>>> Gives errors: 'voids have no value'. It works when writefln is changed to printf, as it returns an int... It would be cool if voids were also allowed to be lazy.
>>>
>>> That's what I get for changing the code at the last minute. :-(
>>
>> :)
>>
>> I get voids have no value for the dotimes example on line:
>> dotimes(10, writef(x++));
>>
> 
> Hmmm, In trying to get the example to work i tried
> dotimes(10, (writef(x++),0));
> 
> To turn the expression to something other than void but
> now it prints:
> [int]0[int]1[int]2[int]3[int]4[int]5[int]6[int]7[int]8[int]9
> and I can't understand why is this happening?

LOL, try this one:

dotimes(10, (writefln("%d %s %f", ++i, new Object, 3.14159f), 0));
August 21, 2006
Tom S wrote:
> Ivan Senji wrote:
>>
>> To turn the expression to something other than void but
>> now it prints:
>> [int]0[int]1[int]2[int]3[int]4[int]5[int]6[int]7[int]8[int]9
>> and I can't understand why is this happening?
> 
> LOL, try this one:
> 
> dotimes(10, (writefln("%d %s %f", ++i, new Object, 3.14159f), 0));

LOL, cool! :)
August 21, 2006
Don Clugston wrote:
> It's not just an improved C++ any more, I think a whole new programming style is developing.

Yes. It's called 'functional programming' <g>

-- 
Niko Korhonen
SW Developer