||= is much needed?

2012-06-12 Thread Hemanth H.M
Would something like : obj[prop] ||= NewProp be useful? -- *'I am what I am because of who we all are'* h3manth.com http://www.h3manth.com *-- Hemanth HM * ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: ||= is much needed?

2012-06-12 Thread David Bruant
Le 12/06/2012 15:27, Hemanth H.M a écrit : Would something like : |obj[prop] ||= NewProp| be useful? ahah, I asked the same question very recently [1]. Answer by Brendan Eich [2]. I definitely agree that default arguments are a decent alternative. I can't recall examples where it wouldn't be

Re: ||= is much needed?

2012-06-12 Thread Rick Waldron
On Tue, Jun 12, 2012 at 10:33 AM, David Bruant bruan...@gmail.com wrote: Le 12/06/2012 15:27, Hemanth H.M a écrit : Would something like : obj[prop] ||= NewProp be useful? There is currently a strawman proposal for the Default Operator, which can be found here:

Re: ||= is much needed?

2012-06-12 Thread Hemanth H.M
Kool, well was looking into use caseswell my first frustration was [1] I'm new to this, how does one write proposals? Is it a wiki? [1] https://twitter.com/GNUmanth/status/208555914733682690 On Tue, Jun 12, 2012 at 8:36 PM, Rick Waldron waldron.r...@gmail.comwrote:

Re: ||= is much needed?

2012-06-12 Thread Rick Waldron
On Tue, Jun 12, 2012 at 11:45 AM, Ryan Florence rpflore...@gmail.comwrote: I use ||= very regularly in ruby and coffeescript, both of which have default arguments. I definitely agree that default arguments are a decent alternative. I can't recall examples where it wouldn't be enough. Do you

Re: ||= is much needed?

2012-06-12 Thread AJ ONeal
+1 I desperately want this in the language. AJ ONeal On Tue, Jun 12, 2012 at 11:14 AM, Rick Waldron waldron.r...@gmail.comwrote: On Tue, Jun 12, 2012 at 11:45 AM, Ryan Florence rpflore...@gmail.comwrote: I use ||= very regularly in ruby and coffeescript, both of which have default

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Rick Waldron wrote: On Tue, Jun 12, 2012 at 11:45 AM, Ryan Florence rpflore...@gmail.com mailto:rpflore...@gmail.com wrote: I use ||= very regularly in ruby and coffeescript, both of which have default arguments. I don't see Ryan's mail. First, as we've discussed in the past, ||=

Re: ||= is much needed?

2012-06-12 Thread Wes Garland
This breaks from JS's C-inspired assignment operators, but perhaps we can live with it. FWIW -- I was confused when I first read ||=, I thought it was supposed to be some kind of Boolean-coercing variant on |=. Now I see that it is more like ?= from GNU make. What do you think of GCC's ?:

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Wes Garland wrote: This breaks from JS's C-inspired assignment operators, but perhaps we can live with it. FWIW -- I was confused when I first read ||=, I thought it was supposed to be some kind of Boolean-coercing variant on |=. Now I see that it is more like ?= from GNU make. We could

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Brendan Eich wrote: Is this (A ? B) ? C : D or A ? (B ? C) : D. We can disambiguate in the formal grammar but readers may rebel. Or A ? (B ? C : D), of course. Just say no to lone ? as new operator. I'm warming up to ?= though! /be ___ es-discuss

Re: ||= is much needed?

2012-06-12 Thread Tom Ellis
I like the sound of ?= too. var a; //later on a ?= 15; It goes with all the other operators that are out there too (!=, =, ==, === etc). Tom On 12 Jun 2012, at 19:04, Brendan Eich wrote: Brendan Eich wrote: Is this (A ? B) ? C : D or A ? (B ? C) : D. We can disambiguate in the formal

Re: ||= is much needed?

2012-06-12 Thread Russell Leggett
On Tue, Jun 12, 2012 at 2:31 PM, Tom Ellis tellis...@gmail.com wrote: I like the sound of ?= too. var a; //later on a ?= 15; It goes with all the other operators that are out there too (!=, =, ==, === etc). +1, useful and intuitive. - Russ Tom On 12 Jun 2012, at 19:04, Brendan

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Russell Leggett wrote: On Tue, Jun 12, 2012 at 2:31 PM, Tom Ellis tellis...@gmail.com mailto:tellis...@gmail.com wrote: I like the sound of ?= too. var a; //later on a ?= 15; It goes with all the other operators that are out there too (!=, =, ==, === etc). +1,

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Brendan Eich wrote: LeftHandSideExpression ?= AssignmentExpression are roughly Let lref = evaluate A. Let lval = GetValue(lref). Let rref = evaluate B. Of course, A should be LeftHandSideExpression and B should be AssignmentExpression. This is pretty simple. We could even grant an

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Updated. Sorry, no ||| instead of ??. Instead, inspired by Wes's GCC reminder, I kept the ?? operator but re-spelled it as ?: and made ??= be spelled ?=. http://wiki.ecmascript.org/doku.php?id=strawman:default_operator The semantics match only undefined. APIs use null as no-object and do not

Re: ||= is much needed?

2012-06-12 Thread John Tamplin
On Tue, Jun 12, 2012 at 3:09 PM, Brendan Eich bren...@mozilla.org wrote: And (to be clear) the semantics for LeftHandSideExpression ?= AssignmentExpression are roughly Let lref = evaluate A. Let lval = GetValue(lref). Let rref = evaluate B. Let rval = GetValue(rref). Throw a

Re: ||= is much needed?

2012-06-12 Thread Allen Wirfs-Brock
On Jun 12, 2012, at 3:26 PM, John Tamplin wrote: On Tue, Jun 12, 2012 at 3:09 PM, Brendan Eich bren...@mozilla.org wrote: And (to be clear) the semantics for LeftHandSideExpression ?= AssignmentExpression are roughly Let lref = evaluate A. Let lval = GetValue(lref). Let rref =

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Heh, I did write *roughly* :-P. Let lref = evaluate LeftHandSideExpression. Let lval = GetValue(lref). Throw a SyntaxError exception if the following conditions are all true: • Type(lref) is Reference is true • IsStrictReference(lref) is true • Type(GetBase(lref)) is Environment Record •

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Ok, that (cited below) was wrong too. This should be right: http://wiki.ecmascript.org/doku.php?id=strawman:default_operator#semantics Comments welcome. Thanks again, I needed some caffeine! /be Brendan Eich wrote: Heh, I did write *roughly* :-P. Let lref = evaluate

Re: ||= is much needed?

2012-06-12 Thread David Herman
On Jun 12, 2012, at 11:02 AM, Brendan Eich wrote: It's possible ?? or however we spell it isn't worth adding, while ?= is. The conditional assignment to default or normalize is the prime use-case. I'm skeptical. You don't foresee f(obj.x ?? defVal) happening a lot? I do. Dave

Fwd: ||= is much needed?

2012-06-12 Thread Rick Waldron
, 2012 at 11:45 AM Subject: Re: ||= is much needed? To: Rick Waldron waldron.r...@gmail.com Cc: David Bruant bruan...@gmail.com, es-discuss@mozilla.org I use ||= very regularly in ruby and coffeescript, both of which have default arguments. I definitely agree that default arguments are a decent

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
On Jun 12, 2012, at 5:57 PM, David Herman dher...@mozilla.com wrote: On Jun 12, 2012, at 11:02 AM, Brendan Eich wrote: It's possible ?? or however we spell it isn't worth adding, while ?= is. The conditional assignment to default or normalize is the prime use-case. I'm skeptical. You

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
Ryan Florence wrote: But if we're adding ?= because we're adding ?: maybe its okay to add ||= while we're at it? That said, I would hate to see ?= get derailed because ||= is dumb. Dumb is too strong. How about YAGNI? Every use-case of || I've seen in JS (almost all with the result of || the

Re: ||= is much needed?

2012-06-12 Thread David Herman
On Jun 12, 2012, at 7:41 PM, Ryan Florence wrote: I'm skeptical. You don't foresee f(obj.x ?? defVal) happening a lot? I do. I can't speak for the world but I've never seen anybody do f(val ||= defVal) in Ruby or CoffeeScript. But I'm not talking about ||=. I'm talking about the

Re: ||= is much needed?

2012-06-12 Thread Brendan Eich
People don't default on the caller side (at the callsite) much, in my experience. Dave may be seeing other sources, but it's extremely rare in my experience to see foo(arg1 || callers_idea_of_default_arg1_value); whereas we all see function foo(a, b, c) { a = a || default_a; b.x

Re: ||= is much needed?

2012-06-12 Thread Axel Rauschmayer
I think it’d be handy when you are taking apart objects (e.g. JSON data). However, you do have the option of merging in default values (e.g. via http://documentcloud.github.com/underscore/#defaults ). On Jun 13, 2012, at 7:52 , Brendan Eich wrote: People don't default on the caller side (at

<    1   2