How Nested Functions Work, part 1
Nick Sabalausky
a at a.a
Wed Sep 2 13:53:07 PDT 2009
"Jeremie Pelletier" <jeremiep at gmail.com> wrote in message
news:h7m6nb$2k8v$1 at digitalmars.com...
>
> The only valid syntax is up there,
Yea, but which one? ;)
> I almost only use delegates in D, since it allows functions pointers,
> delegates, closures and nested functions to be passed. Function pointers
> only allow function pointers, but are useful for C compatibility.
>
> I almost never use delegate literals since closures can be used instead,
> even with a return value (works like 'auto' return values).
>
True, and I also always use "delegate" instead of "function" for basically
same reasons, but only because I've been following this newsgroup enough to
actually know that. And even at that, I still have times when I think "Ok, I
need to pass a chuck of code around, and chunks of code are functions
obviously, so I'll type 'function'...and...oh wait, that's right, I need to
always use 'delegate', even though D does also have the nearly-useless
'function'!"
> void foo(bool delegate() dg) {
> dg();
> }
> foo({return true;});
>
Sure, when there's no parameters (...does that work in D1, or just D2?...),
but even then, I still always end up going though a process like this when
defining foo:
[typing:] void foo([...big pause...]bool myDg(
["No, no, wait, that's not right..."]delegate bool([...another big pause...]
[decide "fuck it" and go look it up]
More information about the Digitalmars-d
mailing list