Ingvar von Schoultz ingvar-v-s at
Sat Aug 30 16:48:21 PDT 2008

Dave Herman wrote:
> The first thing I'd change is to replace 
> the "sugar" keyword with "decorator." I think this would make its 
> purpose clearer and connect it with precedent from other languages.

Indeed they seem similar to python decorators. But "decorator"
suggests that there's something you're decorating. The keywords
that I'm proposing can be used independently.

Suppose you don't like the word |function|, and want to say |fn|
or |lambda| or |closure| instead:

     use sugar fn;
     sugar function fn (func) {return func}
     myArray.sort (fn (a, b) {a - b});

Or suppose you wish that let(a=1){...} would desugar exactly to

     use sugar lt;
     sugar function lt (func) {return func()}
     lt (a=1) {...};

The desugaring that I showed in the thread starter was abbreviated
for simplicity. If one detail is added, keywords can create control
structures, if your programming style has no problems with continue/
/break/return/var getting locked up inside the resulting function:

     use sugar unless, until;
     sugar function unless (cond, work) {if (!cond()) work()}
     sugar function until (cond, work) {while (!cond()) work()}
     unless (x < 42)
     {   until (y > 42)
         {   ++y;

So this sugar is more general-purpose than a decorator.

> Regardless, I don't 
> think we've been considering meta-programming facilities to be on the 
> near-term agenda.

One reason I brought them up now was that Java-style classes were
discussed. Significant parts of this class functionality could
instead be offered by third-party library vendors using these
keywords. We'd get more variation, greater freedom, and much
faster adaptability, than if it's defined in a standards body.

Of course performance becomes a big issue. I think ES implementations
would detect popular patterns and optimize for them. For example,
Java-style classes would undoubtedly become very popular and very
well optimized.

This would be self-reinforcing. Applications would choose patterns
that have high performance on many platforms, and so the optimized
patterns would become even more popular.

Data type is another issue, but it may be too early for that

Ingvar von Schoultz

More information about the Es-discuss mailing list