[DGD]Fwd: Foreach and anonymous functions in DGD

Felix A. Croes felix at dworkin.nl
Sun Jan 28 21:36:24 CET 2001


> From: Lee Salzman <lee.salzman at lvdi.net>
> To: felix at dworkin.nl
> Subject: Foreach and anonymous functions in DGD
>
> (The DGD mailing list seems to be not accepting
>  my post so I'm sending this directly to you. :])
>
>    I've been looking around for other drivers than MudOS
> lately (due to its bloat and lack of maintenance) and
> somewhat decided to settle with DGD. However, certain
> features MudOS provides are definitely convenient and
> I, rmm, hacked one or two of them into DGD(some parts
> more hackish than others), namely foreach() has been
> implemented for both arrays and mappings as well as
> anonymous functions (not hellish-looking lambda
> closures or awkward functionals, but prettier
> looking anonymous functions).
>
>    These modifications, in diff and tarball form,
> can be found at:
>    http://www.lvdi.net/~lee.salzman/dgd-mod.diff.gz
>    http://www.lvdi.net/~lee.salzman/dgd-mod.tar.gz
>
>
>    Whether or not these changes are too controversial
> to be accepted into the main body of code I leave
> to Dworkin. :) 
>    
>    At a glance, foreach() is just a rather simple
> construct that maps down to for(;;) with some
> hidden temporary variables thrown in to handle
> iteration over an array or mapping as appropriate
> (this is only about 50 lines of code or so). Many
> problems ensued over the tokenizer's reserved keyword
> hashing technique, so I just tacked on a simple
> decision tree in the changes in the m ean time
> (how the heck did you generate the hash table? >:]).
>
> ex:
> foreach (string key, int value in ([ "foo" : 3 ]))
>    bar (key, value);
>
>    As for anonymous functions, the implementation
> is vaguely based on lambda lifting. The bulk of
> the work was making the compiler support compilation
> of nested functions (of whatever sort). However, I
> wasn't quite sure how to get a persistent reference
> to a specific function definition in a control block
> so I put in a temporary hack that just generates
> a "pseudo-unique" name for each closure. (which
> of course should also be fixed if it is seen fit
> to incorporate anonymous functions).
>
> ex: 
> sum = evaluate (\int(int x, int y) { return x + y; }, 2, 3);
> => sum == 5
>
>    '\' is the lambda operator. If return type is 
> omitted, mixed is assumed. As they are only anonymous
> functions, you can only refer to global variables or 
> local variables in the anonymous function, as opposed 
> to also in the enclosing function. A corresponding 
> 'function' type was added as well.
>
>   
>                         Lee Salzman (lee.salzman at lvdi.net)

List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list