Closures issues
    Andrei Khropov 
    andkhropov at nospam_mtu-net.ru
       
    Mon Jul 24 03:01:23 PDT 2006
    
    
  
Andrei Khropov wrote:
> 
> Hello everybody.
> 
> There's a reoccuring issue with closures, i.e. downwards FunArg problem
> (http://en.wikipedia.org/wiki/Funarg_problem#Downwards_funarg_problem).
> 
> In simple terms delegates that contain pointer to function that has exited are
> actually point to some garbage. This leads to UB.
> 
> So I would like to clarify situation a bit:
> 
> 1) I.e. should D support full closures (like functional languages do)?
>    Solution is actually simple - allocate local variables that are used by a
> delegate in a heap object 	(of course only if it is actually necessary)
>   ( like here: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/39525
> ).     This will actually enable truly functions as first-class objects and 
>    higher-order functions
>    (because we could return delegates from functions) 
I recently read that C# 2.0 does that:
http://msdn.microsoft.com/msdnmag/issues/06/00/C20/default.aspx#S7
Better keep up with the competition...
-- 
AKhropov
    
    
More information about the Digitalmars-d
mailing list