Speaking of Lisp...

Chris Hansen renselp at gmail.com
Fri Jan 5 23:14:24 PST 2007


(thinking out loud)

One way to circumvent the syntax issue could be to allow maps as part
of function calls -- like a combination of varargs and keyword
arguments:

function foo(x, y, arg_map) { return x + y + arg_map.a + arg_map.b }
foo(1, 2, a: 1, b: 2)

The compiler can recognize the map arguments and turn the method call
into this at compile time:

foo(1, 2, #{'a': 1, 'b': 2})

Then you could make a Hash or Dict using a built-in method call or a
constructor: "new Hash(foo: 1, bar: 2)" or "hash(foo: 1, bar: 2)".
It's a bit heavy syntactically but one advantage of this over a
dedicated syntax is that  people can add their own map types: "new
PrefixTree(wip: 1, wap: 2)".

Just a thought.


-- Chris

On 1/6/07, Chris Double <chris.double at double.co.nz> wrote:
> On 1/6/07, Brendan Eich <brendan at mozilla.org> wrote:
> > Sounds like one vote for a Dictionary class.  Could you cite some
> > URLs documenting Proxy and Dictionary from the Flex SDK (I'm assuming
> > these are not "AS3" but "host" types).
>
> A Dictionary class would be useful I think. Looking around the web for
> 'javascript associative arrays' will show quite a few hits where
> people have hit the problem of objects in the prototype being picked
> up without them realising this would happen.
>
> Although 'hasOwnProperty' can be used to avoid this it doesn't work in
> all cases. For example, in Firefox all objects return true for
> hasOwnProperty('__proto__'). So using an object as a Dictionary has to
> handle issues like this.
>
> Chris.
> --
> http://www.bluishcoder.co.nz
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>



More information about the Es4-discuss mailing list