Lazy eval

Derek Parnell derek at nomail.afraid.org
Mon Aug 21 20:03:07 PDT 2006


On Mon, 21 Aug 2006 19:41:24 -0700, Walter Bright wrote:

> Derek Parnell wrote:
>> On Mon, 21 Aug 2006 16:33:00 -0700, Walter Bright wrote:
>>> The problem with requiring the { } around the argument is that 
>>> programmers just don't like it. I don't think I can make them like it.
>> 
>> Huh? You asked them all? You didn't ask me and I like it. 
> 
> Did you use it before 0.165? 

Yes. However I couldn't release it in Build until GDC caught up to the
ability, so I took it out again.

> Did anyone? Everyone I'd show the { } 
> syntax to reacted with zzzzzz. 

I didn't. 

> I show them the one without, and all of a 
> sudden they are excited about it and can think of all kinds of uses.

And so am I, but now I *also* wary of the pitfalls that this implicit
conversion to delegates open up.
 
> C++ programmers have been trying to do this for over a decade - first 
> with preprocessor macros, and now with expression templates.

And do I give a toss about C++ programming foibles ;-)

> Perhaps what is so off-putting of this feature, as opposed to out, 
> inout, const, implicit conversions, and other effects that require one 
> to look at the interface, is it's very unusual (even unique?) for a 
> C-like language.

Not sure about that. I see the problem with existing calls to functions
suddenly behaving differently with no apparent reason. With this new
ability, a library writer can change the interface and my program will
still compile, but may now behave in unexpected ways.


Let's assume the original API said 

   void SomeFunc(char[] x);

so I code ...

 void xyzzy(inout x)
 {
    char[] r = std.string.format("%d", x);
    x++;
 }
 . . .
 int y = 7;
 SomeFunc( std.string.format("The number is " ~ xyzzy(y)) );


Then the library writer changes this to 

   void SomeFunc(char[] delegate() x);

My code still compiles but there is now no guarantee that my xyzzy()
function will be called. The API function may chose to not call it for some
reason valid to itself. But I'm left scratching my head trying to work out
why my variable 'y' is sometimes being updated and other times not.


-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
22/08/2006 12:49:40 PM



More information about the Digitalmars-d mailing list