simpler, sweeter syntax for modules

Claus Reinke claus.reinke at talk21.com
Fri Mar 23 00:53:46 PDT 2012


> So I gather that the dynamic case would look like:
> 
> system.load(jqueryPath, function(m) {
>    system.load(shimLibPath, function(n) {
>        system.load(corpLibPath, function(o) {
>            system.load(myLibPath, function (p) {
>                import * from m;
>                import * from n;
>                import logHelper from o;
>                import y from p;
>                ...
>            });
>        });
>    });
> });
> 
> Is this correct?  To me this form looks like a poor cousin. Maybe its the
> best we can do?

This isn't part of any official proposal, and hasn't received any interest
when I suggested it earlier, but I'd still like to see some sugar for then-
ables (like promises). Roughly, the let-from form

    { let p <- t; code }     would become    t.then( {| p | code } )

So, if module loaders would return promises, and if let-from was
supported, your example could be written as

let m <- system.load(jqueryPath)
let n <- system.load(shimLibPath)
let o <- system.load(corpLibPath)
let p <- system.load(myLibPath)
import * from m;
import * from n;
import logHelper from o;
import y from p;
...

The details of let-from remain to be worked out, especially which
function form to desugar to, but experience from other languages
(do-notation, computation expressions) suggest that it would be 
very worthwhile (not just for async callbacks), if done right.

Claus
 


More information about the es-discuss mailing list