[D2] How to not full closure?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Wed Jul 30 15:08:12 PDT 2008


bearophile wrote:
> Bruno Medeiros:
>> I think Walter's solution ("using 'scope' to tag function parameters 
>> that do not escape") may be even better. It doesn't add new syntax to 
>> literals, is statically verifiable more "locally", and may have other 
>> uses other than for delegates.
> 
> So to pass a lambda without closure you have to write something like this?
> foo(scope (int x){return x*x;});
> 
> Bye,
> bearophile

I said parameters, not arguments. You'd declared the function like this:

   void foo(scope int delegate(int) dg) {

the function call would remain the same:

   foo((int x){return x*x;});

Seems a better solution, at least at first sight, haven't though much 
about it.

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list