Re: simpler, sweeter syntax for modules

2012-03-23 Thread Claus Reinke
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;

Re: simpler, sweeter syntax for modules

2012-03-23 Thread John J Barton
On Thu, Mar 22, 2012 at 10:32 AM, Brendan Eich bren...@mozilla.org wrote: John J Barton wrote: I guess you mean: a special form evaluated before the outer function runs? Surely this form is not off-line. No, before anything in the containing Program (up to the script container) runs.

Re: simpler, sweeter syntax for modules

2012-03-23 Thread Brendan Eich
John J Barton wrote: Brendan, your argument above makes it sound like import x from Bar.js does not block and thus would not starve the UI rendering. How can that be? While parsing (which can be done very early, as TCP segments come in, with some assembly across boundaries required),

Re: simpler, sweeter syntax for modules

2012-03-23 Thread Claus Reinke
2. Also we are not losing static binding by having the names injected by static syntactic forms depend on control flow dynamics. When statically checkable constraints meet dynamic load/eval, it isn't necessary to have a strict static/dynamic split. It would be possible to adopt a multi-staged

Re: simpler, sweeter syntax for modules

2012-03-23 Thread Brendan Eich
Claus Reinke wrote: When statically checkable constraints meet dynamic load/eval, it isn't necessary to have a strict static/dynamic split. It would be possible to adopt a multi-staged design, where there are multipe dynamic phases, each with its own preceding static phase: no code runs without

Re: simpler, sweeter syntax for modules

2012-03-22 Thread David Herman
On Mar 21, 2012, at 9:28 PM, John J Barton wrote: equals makes sense when it is assigment: module Bar = load(bar.js); It's not an assignment, though. Which is why Brendan didn't like it in the first place, since he felt programmers would get confused that it was a dynamic assignment

Re: simpler, sweeter syntax for modules

2012-03-22 Thread David Herman
On Mar 21, 2012, at 9:41 PM, Brendan Eich wrote: Perhaps Python has the right syntax, then? from foo.js import foo; import foo.js as Foo; I suppose we could. I always thought this was an awkward choice on Python's part. The first line always reminds me of the Yinglish constructions my

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Brendan Eich
David Herman wrote: On Mar 21, 2012, at 9:28 PM, John J Barton wrote: equals makes sense when it is assigment: module Bar = load(bar.js); It's not an assignment, though. Which is why Brendan didn't like it in the first place, since he felt programmers would get confused that it was a

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Gavin Barraclough
On Mar 21, 2012, at 3:28 PM, David Herman wrote: * importing with renaming: import { draw: drawGun }from cowboy.js, { draw: drawWidget } from widgets.js; Hey Dave, This all looks really nice! - the only thing that threw me was the export rename – I intuitively expect the

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Peter van der Zee
On Wed, Mar 21, 2012 at 11:28 PM, David Herman dher...@mozilla.com wrote: * importing with renaming:    import { draw: drawGun }    from cowboy.js,           { draw: drawWidget } from widgets.js; The brackets don't seem necessary (at least not from a parsing perspective). Maybe drop them?

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Andreas Rossberg
On 22 March 2012 10:23, Peter van der Zee e...@qfox.nl wrote: On Wed, Mar 21, 2012 at 11:28 PM, David Herman dher...@mozilla.com wrote: * importing with renaming: import { draw: drawGun }from cowboy.js, { draw: drawWidget } from widgets.js; The brackets don't seem

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Herby Vojčík
David Herman wrote: On Mar 21, 2012, at 9:28 PM, John J Barton wrote: equals makes sense when it is assigment: module Bar = load(bar.js); It's not an assignment, though. Which is why Brendan didn't like it in the first place, since he felt programmers would get confused that it was a

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Andreas Rossberg
On 22 March 2012 02:35, David Herman dher...@mozilla.com wrote: Follow-up: I've factored out these two alternative approaches, both of which I think are defensible. Grammars: http://wiki.ecmascript.org/doku.php?id=harmony:modules#syntax Nice! One question: is there a reason why you not

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Andreas Rossberg
On 22 March 2012 07:12, David Herman dher...@mozilla.com wrote: On Mar 21, 2012, at 9:01 PM, Axel Rauschmayer wrote: I like variant B, because it follows the rules: - module = define a module - import = extract something out of a module As Dave already mentioned, that is my stance, too.

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Andreas Rossberg
On 22 March 2012 07:33, Brendan Eich bren...@mozilla.org wrote: David Herman wrote: On Mar 21, 2012, at 9:28 PM, John J Barton wrote: equals makes sense when it is assigment: module Bar = load(bar.js); It's not an assignment, though. Which is why Brendan didn't like it in the first

Re: simpler, sweeter syntax for modules

2012-03-22 Thread brad dunbar
This is great stuff. I've got a quick question about the `as` keyword. import 'foo.js' as Foo; Is there any reason we can't simply do var Foo = import 'foo.js'; When looking for the source of a variable, I often search for /Foo =/ to discern it's origin and it only seems natural that giving

RE: simpler, sweeter syntax for modules

2012-03-22 Thread Domenic Denicola
/runnable.js [5]: https://github.com/visionmedia/mocha/blob/master/lib/suite.js From: es-discuss-boun...@mozilla.org [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Andreas Rossberg Sent: Thursday, March 22, 2012 07:55 To: es-discuss Subject: Re: simpler, sweeter syntax for modules One point

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Kevin Smith
Correct me if I have any of this wrong, but modules don't need to be callable for the jQuery use case: // jquery.js export function $(...) { ... } // program.js import $ from path/to/jquery.js; $(#elem).whatever We don't need node style modules-as-classes either: //

Re: simpler, sweeter syntax for modules

2012-03-22 Thread David Herman
On Mar 22, 2012, at 4:55 AM, Andreas Rossberg wrote: One point that I haven't seen mentioned yet (and it is unrelated to syntax): export call makes me cringe -- making modules callable is not just weird, it seems completely future-hostile to the possibility of having parameterized modules.

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Russell Leggett
That said, it requires no more code to say: // jquery.js export function $(selector) { ... } ... // client import $ from jquery.js; let elements = [foo, bar, baz].map($); $(quux).style(...); So maybe people have over-sold the importance of callable modules. In

Re: simpler, sweeter syntax for modules

2012-03-22 Thread David Herman
On Mar 22, 2012, at 4:46 AM, Andreas Rossberg wrote: Nice! One question: is there a reason why you not just define Program ::= ModuleBody ? No exports from a Program. Dave ___ es-discuss mailing list es-discuss@mozilla.org

Re: simpler, sweeter syntax for modules

2012-03-22 Thread David Herman
On Mar 22, 2012, at 4:48 AM, Andreas Rossberg wrote: On 22 March 2012 07:33, Brendan Eich bren...@mozilla.org wrote: But why make misleading syntax? More of a question for John: why write |load(bar.js)| there, looking for all the world like a function call evaluated in order at runtime,

Re: simpler, sweeter syntax for modules

2012-03-22 Thread John J Barton
On Wed, Mar 21, 2012 at 11:33 PM, Brendan Eich bren...@mozilla.org wrote: David Herman wrote: On Mar 21, 2012, at 9:28 PM, John J Barton wrote: equals makes sense when it is assigment:   module Bar = load(bar.js); It's not an assignment, though. Which is why Brendan didn't like it in the

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Andreas Rossberg
On 22 March 2012 16:30, David Herman dher...@mozilla.com wrote: On Mar 22, 2012, at 4:46 AM, Andreas Rossberg wrote: Nice! One question: is there a reason why you not just define Program ::= ModuleBody ? No exports from a Program. Except that the syntax currently includes that.

RE: simpler, sweeter syntax for modules

2012-03-22 Thread Luke Hoban
The bracket syntax is pretty confusing with object literal notation imo. It shouldn't be too confusing, and the similarity is in fact intentional. You should read import as destructuring (and export as the inverse structuring, if you want). I agree that this isn't really a question

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Brendan Eich
Andreas Rossberg wrote: I still wonder why you think it is so confusing to use the equality sign for module bindings. It is overloaded to mean define as and assign in almost all language that use it for the latter, and for different semantic categories, too. I never witnessed anybody being

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Brendan Eich
David Herman wrote: The 'at' might be appropriate but it just looks like an unfinished thought: the module foo at 'foo.js' ...what? Both the import-as and module-= forms state what the declaration is doing. The former declares it is importing the module; the latter declares it is

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Brendan Eich
John J Barton wrote: I guess you mean: a special form evaluated before the outer function runs? Surely this form is not off-line. No, before anything in the containing Program (up to the script container) runs. Modules are prefetched, not loaded by a nested event loop that violates

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Allen Wirfs-Brock
On Mar 22, 2012, at 9:12 AM, Luke Hoban wrote: The bracket syntax is pretty confusing with object literal notation imo. It shouldn't be too confusing, and the similarity is in fact intentional. You should read import as destructuring (and export as the inverse structuring, if you want).

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Brendan Eich
Luke Hoban wrote: At least half the times I've shown object destructuring or module import renaming syntax I've gotten don't you have that backwards? remarks. I can't say I have a better recommendation for the general object destructuring syntax, but I expect this to be a point of

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Brendan Eich
Allen Wirfs-Brock wrote: I also find myself getting it backwards, but it helps me to remember that for destructing assignment the target needs to be an arbitrary LHS which won't really fit well to the right of the : You mean left, not right. ;-) /be

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Allen Wirfs-Brock
On Mar 22, 2012, at 10:56 AM, Brendan Eich wrote: Allen Wirfs-Brock wrote: I also find myself getting it backwards, but it helps me to remember that for destructing assignment the target needs to be an arbitrary LHS which won't really fit well to the right of the : You mean left, not

Re: simpler, sweeter syntax for modules

2012-03-22 Thread John J Barton
On Thu, Mar 22, 2012 at 10:32 AM, Brendan Eich bren...@mozilla.org wrote: John J Barton wrote: I guess you mean:  a special form evaluated before the outer function runs? Surely this form is not off-line. No, before anything in the containing Program (up to the script container) runs.

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Brendan Eich
John J Barton wrote: Second, we need a solution for asynchronous loading with run-time selection. We use it now and as we move to much better network layers we will use it a lot more. Of course. This is what the http://wiki.ecmascript.org/doku.php?id=harmony:module_loaders API is all about.

Re: simpler, sweeter syntax for modules

2012-03-22 Thread John J Barton
On Thu, Mar 22, 2012 at 1:54 PM, Brendan Eich bren...@mozilla.org wrote: John J Barton wrote: Second, we need a solution for asynchronous loading with run-time selection. We use it now and as we move to much better network layers we will use it a lot more. Of course. This is what the

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Sam Tobin-Hochstadt
On Thu, Mar 22, 2012 at 5:11 PM, John J Barton johnjbar...@johnjbarton.com wrote: The module solution posted seems to have a top-notch solution for the static case but the dynamic case is buried in the loader. I don't really understand what you mean by buried in the loader. Here's the dynamic

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Claus Reinke
Btw, another question that has bugged me lately: with 1JS, what happens when I do a sloppy-mode direct eval on a program string containing a module declaration? In global scope? In local scope? It's a good question, and one I've thought about some. This could use some whiteboard time -- let's

Re: simpler, sweeter syntax for modules

2012-03-22 Thread John J Barton
On Thu, Mar 22, 2012 at 3:06 PM, Sam Tobin-Hochstadt sa...@ccs.neu.edu wrote: On Thu, Mar 22, 2012 at 5:11 PM, John J Barton johnjbar...@johnjbarton.com wrote: The module solution posted seems to have a top-notch solution for the static case but the dynamic case is buried in the loader. I

Re: simpler, sweeter syntax for modules

2012-03-22 Thread John J Barton
On Thu, Mar 22, 2012 at 4:54 PM, Brendan Eich bren...@mozilla.org wrote: John J Barton wrote: If I go back to my previous question, can we understand what should happen here? if (version === 1)  import y from 'lib1.js'; else  import y from 'lib2.js'; Again, no. No, we can't understand

Re: simpler, sweeter syntax for modules

2012-03-22 Thread Brendan Eich
John J Barton wrote: On Thu, Mar 22, 2012 at 4:54 PM, Brendan Eichbren...@mozilla.org wrote: John J Barton wrote: If I go back to my previous question, can we understand what should happen here? if (version === 1) import y from 'lib1.js'; else import y from 'lib2.js'; Again, no. No,

simpler, sweeter syntax for modules

2012-03-21 Thread David Herman
H'lo, Thanks to some a-maz-ing [1] work by Andreas Rossberg (I'll spare the gory algorithmic details), the linking process no longer needs the syntactic distinction that static module bindings are only created via the `module` (contextual) keyword. This frees us up to simplify the syntax,

RE: simpler, sweeter syntax for modules

2012-03-21 Thread Luke Hoban
-Original Message- From: es-discuss-boun...@mozilla.org [mailto:es-discuss-boun...@mozilla.org] On Behalf Of David Herman Sent: Wednesday, March 21, 2012 3:29 PM To: es-discuss discussion Subject: simpler, sweeter syntax for modules H'lo, Thanks to some a-maz-ing [1] work by Andreas Rossberg (I'll

Re: simpler, sweeter syntax for modules

2012-03-21 Thread Axel Rauschmayer
I like it, more in line with AMDs and Node.js modules. Honest question: Are nested modules really needed? On Mar 21, 2012, at 23:28 , David Herman wrote: H'lo, Thanks to some a-maz-ing [1] work by Andreas Rossberg (I'll spare the gory algorithmic details), the linking process no longer

Re: simpler, sweeter syntax for modules

2012-03-21 Thread Axel Rauschmayer
: simpler, sweeter syntax for modules H'lo, Thanks to some a-maz-ing [1] work by Andreas Rossberg (I'll spare the gory algorithmic details), the linking process no longer needs the syntactic distinction that static module bindings are only created via the `module` (contextual) keyword

Re: simpler, sweeter syntax for modules

2012-03-21 Thread Kris Kowal
On Wed, Mar 21, 2012 at 4:05 PM, Axel Rauschmayer a...@rauschma.de wrote: Honest question: Are nested modules really needed? There is a chance that they would be useful for bundling. Modules can’t be concatenated. Kris Kowal ___ es-discuss mailing

Re: simpler, sweeter syntax for modules

2012-03-21 Thread David Herman
On Mar 21, 2012, at 3:44 PM, Luke Hoban wrote: Great to see the updates. A couple of questions: import foo.js as Foo; import foo from foo.js; These two forms look rather confusingly similar given how different they are, and the inversion of order of where the filename lives doesn't

Re: simpler, sweeter syntax for modules

2012-03-21 Thread Kevin Smith
This looks really nice! kevin ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: simpler, sweeter syntax for modules

2012-03-21 Thread David Herman
On Mar 21, 2012, at 4:25 PM, Kris Kowal wrote: On Wed, Mar 21, 2012 at 4:05 PM, Axel Rauschmayer a...@rauschma.de wrote: Honest question: Are nested modules really needed? There is a chance that they would be useful for bundling. Modules can’t be concatenated. Yeah, I believe that's the

Re: simpler, sweeter syntax for modules

2012-03-21 Thread Axel Rauschmayer
I like variant B, because it follows the rules: - module = define a module - import = extract something out of a module But I would use a keyword instead of = (due to the reason that you mentioned). Compare: module Bar = bar.js; module Bar is bar.js; module Bar from bar.js;

Re: simpler, sweeter syntax for modules

2012-03-21 Thread Brendan Eich
David Herman wrote: On Mar 21, 2012, at 3:44 PM, Luke Hoban wrote: Great to see the updates. A couple of questions: import foo.js as Foo; import foo from foo.js; [snip] Andreas also didn't like the inversion of order. I came to this because earlier versions of the syntax were

Re: simpler, sweeter syntax for modules

2012-03-21 Thread Brendan Eich
David Herman wrote: On Mar 21, 2012, at 3:44 PM, Luke Hoban wrote: Great to see the updates. A couple of questions: import foo.js as Foo; import foo from foo.js; [snip] Andreas also didn't like the inversion of order. I came to this because earlier versions of the syntax were