Lazy eval
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Wed Aug 23 12:44:55 PDT 2006
Stewart Gordon wrote:
> Frank Benoit wrote:
>
>>>> func( char[] a ) vs. func( char[] delegate() dg )
>>>>
>>>> func( funcRetInt() ); vs. func( &funcRetInt );
>>>
>>> If that's the case, then something's wrong. If funcRetInt returns a
>>> char[], despite the name, then funcRetInt() is of type char[]. Therefore
>>> it should match this first.
>>
>>
>> This is the first example, showing a ambiguity
>> func( char[] a ) vs. func( char[] delegate() dg )
>
>
> If one overload matches exactly, it goes without saying that that's the
> one that's called. As such, the programmer would do
>
> func("qwert");
>
> to call the first, and
>
> func({ return "qwert"; });
>
> to call the second. Just like in any other case.
That's what I would have thought as well, but its already been said that these cases are
considered ambiguous... For example, the following code:
# module lazy0 ;
#
# import std .stdio ;
#
# void foo (char[] txt) {
# writefln(`%s`c, txt);
# }
#
# void foo (char[] delegate () expr) {
# writefln(`%s`c, expr());
# }
#
# void main () {
# foo(`Alpha`c);
# }
Produces this error:
# lazy0.d(14): function lazy0.foo called with argument types:
# (char[5])
# matches both:
# lazy0.foo(char[])
# and:
# lazy0.foo(char[] delegate())
>> This is a second example, which has no relation to the first.
>> func( funcRetInt() ); vs. func( &funcRetInt );
>
>
> In that case, I don't get what your problem is.
>
>> And the "vs." is not a object reference. Sorry.
>
>
> Pardon?
>
>>>> { "abc" } => char[] delegate()
>>>
>>> That syntax looks confusingly like an array initialiser....
>>
>>
>> the '=>' was not a syntax proposal
>> "{ "abc" }" /is of type/ "char[] delegate()"
>
>
> The '=>' doesn't look anything like an array initialiser either. Unless
> there's some other kind of array initialiser that I haven't discovered
> yet....
> Wasn't it obvious that I was talking about the bit to the left of those
> two characters?
>
The only thing I can think of is the PHP format:
# $foo = array(
# 'Alpha' => 3 ,
# 'Beta' => 6
# );
As far as I know, the D way is to use a colon (:) for this sort of thing. Although the
bit on the left doesn't look like an array initialiser either, in terms of D, as they use
brackets rather than braces.
# const int[] foo = [3, 6, 9] ;
Static structure literals do use braces, however, so there's still some ambiguity.
# struct S { int foo; float bar; }
#
# static S MyS = {42, 3.14} ;
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list