D doesn't have real closures

Julio César Carrascal Urquijo jcarrascal at gmail.com
Thu Sep 13 19:11:23 PDT 2007


Guillaume B. wrote:
> Is there something wrong with this? ... Well, real closures would be much
 > nicer, but I want to know if I'm missing something...
> 
>  Thanks,
> 
>  Guillaume

Yes, first you are binding function arguments. In the inner function you 
can't use the outer function's variables without passing them as 
arguments and if you accidentally use one of them the compiler wont help 
you detect it.

The second problem is that it's too cumbersome to use. The easier it is 
to use a feature the more uses you'll find.

One of the examples in the article is ported from JavaScript where it is 
wildly used for it's elegance and because it works. It works in D but I 
don't think any D programmer will use it because it looks horrible in D.

If you force a programmer to bind all variables to get something that 
works like a closure he'll settle with another alternative.

That's the problem I see.



More information about the Digitalmars-d-announce mailing list