On Fri, Jul 23, 2010 at 10:20 AM, Kris Kowal <[email protected]> wrote:
> On Fri, Jul 23, 2010 at 10:08 AM, Trans <[email protected]> wrote: > > [0, 1, 2, 3].map( f(x) {x * x} ) > > [0, 1, 2, 3].map( fn(x) {x * x} ) > > [0, 1, 2, 3].map( y(x) {x * x} ) > > Any of these seem a much nicer choice than '#', IMHO. > > While I agree on principle, the real challenge here is to find syntax > that will not break existing programs by promoting an existing > variable name to a keyword. Otherwise, you'd have to look ahead to > the curly brace block to distinguish the variable name from the > function keyword. It's been a long time since I wrote a parser of > this kind, but as I recall, looking ahead is generally hacky. > > function expression: name, argument list, block > You're correct. Once the parser sees the identifier followed by an open paren it would need to parser forward through the tokens until after the closing paren and look to see if it's an open brace. The parser can then determine whether the initial identifier is a call or an anonymous function. As you can imagine the parse would need to have near infinite lookahead since it has to read through an undetermined number of tokens before it can make a decision. > > Of course, if that approach were taken, the spec might as well forgo > having a function keyword at all and use the name or absence of a name > to distinguish a named and anonymous function expression. But again, > I expect there would be resistance to looking ahead. > > Kris Kowal > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss > -- Bryan http://bryan-kyle.blogspot.com @bryan_kyle
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

