Re: please add orEqual operator

2015-08-10 Thread Andrea Giammarchi
On Mon, Aug 10, 2015 at 5:42 PM, joe joe...@gmail.com wrote: Isn't this what switch statements are for? Perhaps a condensed operator version of a switch would be useful? if (a == 0 : 1 : 2) { } switch does eqeqeq comparison so is not exactly the same `switch(1) { case true:

Re: please add orEqual operator

2015-08-10 Thread myemailum14
I one day writing js thought why there is no operator for ||= there should be syntax makes sense, then i learned some ruby and it had this already. Now i was convinced it makes sense afterall. On Mon, Aug 10, 2015 at 1:15 PM, joe joe...@gmail.com wrote: I actually like `[1, 2, 3, 4, 5,

Re: please add orEqual operator

2015-08-10 Thread Caitlin Potter
I've had to track down vendor keywords to force C/C++ compilers to inline functions more than once, after the idiot thing's optimizers failed to do so, not even when I was using the inline keyword Off topic, but remember that inlining isn’t always an optimization, and the compiler’s

Re: please add orEqual operator

2015-08-10 Thread Andrea Giammarchi
well On Mon, Aug 10, 2015 at 6:15 PM, joe joe...@gmail.com wrote: I actually like `[1, 2, 3, 4, 5, 6].contains(a)` better, too. The question is, will engines actually optimize it. if the entire environment never touches even by accident the `Array.prototype` I don't see why that couldn't be

Re: please add orEqual operator

2015-08-10 Thread joe
I actually like `[1, 2, 3, 4, 5, 6].contains(a)` better, too. The question is, will engines actually optimize it. I have to admit, I don't trust people who say VMs or compilers will do the optimizing for you. I've had to track down vendor keywords to force C/C++ compilers to inline functions

Re: please add orEqual operator

2015-08-10 Thread Brendan Eich
Please search for older proposals on ecmascript.org. You'd find http://wiki.ecmascript.org/doku.php?id=strawman:default_operator ES6 parameter default values took a look of wind out of this one's sails. /be myemailu...@gmail.com wrote: it could be used like this: if ( a == 1 ||= 2 ||=3

Re: please add orEqual operator

2015-08-10 Thread joe
Isn't this what switch statements are for? Perhaps a condensed operator version of a switch would be useful? if (a == 0 : 1 : 2) { } Or perhaps something similar to the set version, but without the set: if (a of 1, 2, 3, 4, 5, 6) { } One could do this as a standard lib

Re: please add orEqual operator

2015-08-10 Thread Tab Atkins Jr.
On Mon, Aug 10, 2015 at 1:53 PM, Brendan Eich bren...@mozilla.org wrote: Please search for older proposals on ecmascript.org. You'd find http://wiki.ecmascript.org/doku.php?id=strawman:default_operator ES6 parameter default values took a look of wind out of this one's sails. You're

Re: please add orEqual operator

2015-08-10 Thread Isiah Meadows
The original idea was a default assign operator, like CoffeeScript's `?=`. And the idea of testing multiple values is currently best done with `switch` statements. I would love a simpler alternative, though. (This is something that engines could simply desugar, though, much like default arguments

Re: please add orEqual operator

2015-08-10 Thread Herby Vojčík
myemailu...@gmail.com wrote: I one day writing js thought why there is no operator for ||= there The problem with || (and, consequently, ||=) is that it uses ToBoolean. We have all used to it, but I'd bet what we mostly want is if (x == null) ..., so I think ||= should NOT be added to the

Re: please add orEqual operator

2015-08-10 Thread Isiah Meadows
Agreed. On Mon, Aug 10, 2015, 20:41 Brendan Eich bren...@mozilla.org wrote: Oops, sorry. You were punning with pattern-matching there ;-). Can this thread die? /be Tab Atkins Jr. wrote: On Mon, Aug 10, 2015 at 1:53 PM, Brendan Eichbren...@mozilla.org wrote: Please search for older

Re: please add orEqual operator

2015-08-10 Thread joe
I'm talking about cases where a failure to inline one function led to an order of magnitude performance loss. As a general rule, I only inline functions when I can demonstrate a measurable and significant performance gain, for the reasons you listed. My point is just that you shouldn't trust

Re: please add orEqual operator

2015-08-10 Thread joe
Do you know *why* python gets away with that, though? It forcibly amortizes the GC cost by using a hybrid reference counting/cyclic collector scheme. That's not exactly fast, either, which is why no one else does it. On Mon, Aug 10, 2015 at 2:06 PM, Tab Atkins Jr. jackalm...@gmail.com wrote:

Re: please add orEqual operator

2015-08-10 Thread Jordan Harband
fwiw, just like String#includes, contains has been renamed to Array#includes (see https://github.com/tc39/Array.prototype.includes/) On Sun, Aug 9, 2015 at 8:41 PM, Isiah Meadows isiahmead...@gmail.com wrote: Or, there is the likely ES7 Array#contains for comparing multiple numbers. ```js

Re: please add orEqual operator

2015-08-10 Thread Peter van der Zee
On Mon, Aug 10, 2015 at 3:50 AM, myemailu...@gmail.com wrote: Isn't prop ||= 0; better than prop = prop || 0; and it can be even defined like this. prop ||= var1 ||= var2 ||= 0; but then i dont know how we can use it ike this if (num == 3 ||=4 ||=6) Sounds like you want two operators;

Re: please add orEqual operator

2015-08-10 Thread myemailum14
Thanks I'll be searching through archive, and yea i think this is something very simple and yet innovative. On Mon, Aug 10, 2015 at 3:55 AM, Peter van der Zee e...@qfox.nl wrote: On Mon, Aug 10, 2015 at 3:50 AM, myemailu...@gmail.com wrote: Isn't prop ||= 0; better than prop = prop ||

Re: please add orEqual operator

2015-08-09 Thread Michael A. Smith
I was going to suggest a Set, now that ECMA has them… http://www.ecma-international.org/ecma-262/6.0/index.html#sec-set-objects ```js if ((new Set([1,2,3,5]).has(a)) { // stuff } ``` On Sun, Aug 9, 2015 at 4:20 PM myemailu...@gmail.com wrote: it could be used like this: if ( a == 1

please add orEqual operator

2015-08-09 Thread myemailum14
it could be used like this: if ( a == 1 ||= 2 ||=3 ||=5) { //do something if a is either 1,2,3,5} and it could be used like this a || = 0 // a = a || 0 thanks ___ es-discuss mailing list es-discuss@mozilla.org

Re: please add orEqual operator

2015-08-09 Thread Alexander Jones
`a ||= b` looks like an in-place logical or, like `+=`. `a = a || b` would have very different semantics to that which you propose. In Python this would be written: ```python if a in [1, 2, 3, 5]: # stuff ``` In JS we have similar but slightly less semantic: ```js if ([1, 2, 3,

Re: please add orEqual operator

2015-08-09 Thread myemailum14
why create an array when there can be an operator. I think if we do survey people will like this, ||=, it's more expressive. On Sun, Aug 9, 2015 at 9:41 PM, Isiah Meadows isiahmead...@gmail.com wrote: Or, there is the likely ES7 Array#contains for comparing multiple numbers. ```js [1, 2,

Re: please add orEqual operator

2015-08-09 Thread myemailum14
Isn't prop ||= 0; better than prop = prop || 0; and it can be even defined like this. prop ||= var1 ||= var2 ||= 0; but then i dont know how we can use it ike this if (num == 3 ||=4 ||=6) On Sun, Aug 9, 2015 at 9:47 PM, myemailu...@gmail.com wrote: why create an array when there can be

Re: please add orEqual operator

2015-08-09 Thread Isiah Meadows
Or, there is the likely ES7 Array#contains for comparing multiple numbers. ```js [1, 2, 3].contains(value); ``` As for the operator proposed here, there's already an existing proposal for a safer version which doesn't coerce: http://wiki.ecmascript.org/doku.php?id=strawman:default_operator. On