Dynamic closure vs static closure

Robert Fraser fraserofthenight at gmail.com
Sat Oct 25 17:26:51 PDT 2008


Frank Benoit wrote:
> It is great to hear that this issue is getting solved.
> How will be the now syntax?
> 
> I wonder if the distinction between dynamic/static closure shall be done
> on the calling site, or the called site.
> 
> void foo( void delegate() dg ){
> }
> // -or-
> void foo2( void delegate() dg ){
> }
> 
> void bar(){
>   int i;
>   foo({
>     i++;
>   });
>   // -or-
>   foo( scope {
>     i++;
>   });
> }
> 
> Because I think, the foo method/function signature has to define if the
> delegate is escaping or not. The caller might not know it.
> 
> If the signature defines this, the compiler can check that and give more
> safety.

What if heap delegates were implicitly castable to stack delegates? That 
way, things that needed heap delegates could demand them, and things 
that didn't care would be OK either way?



More information about the Digitalmars-d mailing list