Prev: FAQ Topic - How can I see in javascript if a web browser acceptscookies? (2010-06-16)
Next: FAQ Topic - How can I see in javascript if a web browser accepts cookies? (2010-06-16)
From: Thomas 'PointedEars' Lahn on 16 Jun 2010 20:53 Lasse Reichstein Nielsen wrote: > "Dmitry A. Soshnikov" writes: >> Lasse Reichstein Nielsen wrote: >>> The pattern >>> [x,y] = [e1,e2]; >>> should be detectable at compile time, so the introduction of the >>> intermediate array can be optimized away. >> >> Moreover, it can be done syntactically without brackets, as in Python: No, it can't. Check your assumptions. >> x, y = e1, e2; > > I'd prefer that. The two of you are missing the ambiguity here which prevents that from working as intended in JavaScript already. That is _not_ a destructuring assignment in ECMAScript implementations: it is evaluating x, assigning e1 to y, and evaluating e2. Changing the semantics here would break a lot of existing scripts, and is therefore not going to happen. > Or > (x,y) = (e1,e2); // except it's ambiguous with the stupid comma > operator. That is why it should not be specified or implemented so; the LHS must evaluate to y, and the RHS must evaluate to e2. The Mozilla people (Brendan Eich?) picked the sensible way to provide this feature already. > But then, I think any modern type system should have arbitrary tuples. But thanks to the comma operator, that syntax would not be backwards compatible in ECMAScript implementations. It is highly doubtful that it would be implemented so. So we will probably have to live with Array initializers als tuple replacement. > Heck, I've seen languages with a swap primitive :) > x :=: y; I cannot say I like that a lot either. I also do not think it is a pattern useful often enough for it to deserve any special syntax; I have not used it in production code for a decade or so, thanks to efficient built-in sort implementations. The use of the destructuring assignment here is more of a happy coincidence; the feature was designed for extracting elements from Arrays instead. PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
From: Evertjan. on 17 Jun 2010 05:45 Dmitry A. Soshnikov wrote on 16 jun 2010 in comp.lang.javascript: > Swapping without "third" can be done with simple arithmetic operations: > > A = A - B > B = A + B > A = B - A > Many many years ago, on a microprocessor called 2650, there was an assembler opcode called: swab ... some programmers over here thought this was the native spelling of swap. However it ment "swap registers a and b" -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
From: rf on 17 Jun 2010 06:07 "Evertjan." <exjxw.hannivoort(a)interxnl.net> wrote in message news:Xns9D9A77ADAEDF1eejj99(a)194.109.133.242... > Dmitry A. Soshnikov wrote on 16 jun 2010 in comp.lang.javascript: > >> Swapping without "third" can be done with simple arithmetic operations: >> >> A = A - B >> B = A + B >> A = B - A >> > > Many many years ago, > on a microprocessor called 2650, Hey, I had one of those. On a development board so one could solder stuff like expansion ports and an extra K of memory onto it. Great fun :-) Can't remember much of the assembly language though after 35 years, except that it was a bloody whole lot different to the IBM System 360 Assembler I was then currently being employed to churn out line by tedious line.
From: Evertjan. on 17 Jun 2010 06:22 rf wrote on 17 jun 2010 in comp.lang.javascript: > > "Evertjan." <exjxw.hannivoort(a)interxnl.net> wrote in message > news:Xns9D9A77ADAEDF1eejj99(a)194.109.133.242... >> Dmitry A. Soshnikov wrote on 16 jun 2010 in comp.lang.javascript: >> Many many years ago, >> on a microprocessor called 2650, > > Hey, I had one of those. On a development board so one could solder > stuff like expansion ports and an extra K of memory onto it. > > Great fun :-) > > Can't remember much of the assembly language though after 35 years, I bought 64 kiloBytes of memory from the States by post-order for 1000 guilders, then about $ 400 ?, while mainframe IBM memory was about $ 100.000 for the same amount. We could marvel doing a register exor "XOR0" with itself, sparing an extra processor cycle from setting 000000 in the same register, speed mattered in that era. > except that it was a bloody whole lot different to the IBM System 360 > Assembler I was then currently being employed to churn out line by > tedious line. Philips had programmed a 2650 cross-assembler on the 360 btw. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
From: Dmitry A. Soshnikov on 17 Jun 2010 06:53
On 17.06.2010 13:45, Evertjan. wrote: > Dmitry A. Soshnikov wrote on 16 jun 2010 in comp.lang.javascript: > >> Swapping without "third" can be done with simple arithmetic operations: >> >> A = A - B >> B = A + B >> A = B - A >> > > Many many years ago, > on a microprocessor called 2650, > there was an assembler opcode called: > > swab > > .. some programmers over here thought > this was the native spelling of swap. > > However it ment "swap registers a and b" > Oh, didn't know; historically interesting, thanks. Dmitry. |