DMD 0.165 release
Sean Kelly
sean at f4.ca
Mon Aug 21 12:37:15 PDT 2006
Walter Bright wrote:
> Sean Kelly wrote:
>> Thanks. I suppose it's worth mentioning that lazy evaluation can
>> result in some confusing errors similar to those encountered with
>> macro functions vs. normal functions. For example:
>>
>> void fn( char delegate() ch )
>> {
>> if( ch() == 'c' || ch() == 'd' )
>> {
>> printf( "match\n" );
>> }
>> }
>>
>> size_t pos = 0;
>> char[] buf = "abdc";
>>
>> fn( buf[++pos] );
>>
>> The above code would print "match" because pos would be incremented
>> twice. This makes API changes from the classic to lambda syntax a
>> risky venture, as it risks silently breaking once-working code.
>
> It doesn't break existing once-working code, because the example shown
> will not compile with 0.164 and earlier compilers.
I was thinking more of converting an API call from:
void fn( char ch );
to:
void fn( char delegate() ch );
Both accept the same parameters under DMD 165, but the result may be
different. But this is something library developers simply must keep in
mind more than a problem with the technique itself. It would be easy
enough to document how the supplied delegate is evaluated.
Sean
More information about the Digitalmars-d-announce
mailing list