RE: ES5 left-to-right evaluation order issues

2009-11-20 Thread Allen Wirfs-Brock
Since I talked about valueOf in my original message I'm going to interpret 
Oliver's comment as saying that even in ES3, without getter/setter extensions, 
you can still observed the separation of evaluation from coercion.  That's 
correct. In general, the way the ES3 (and 5) spec is written for binary 
operators of the form expr1 op expr2 any coercion of the value of expr1 types 
place after the evaluation of expr2.  Since expr2 can potentially be an 
arbitrary expression that includes function calls, side-effects can be 
generated whi8le evaluating expr2 that are observed to occur before any 
side-effects from coercion (side-effects of valueOf, etc.) of expr1.

Fixing this would require substantial changes to the specification and to 
existing implementations that I doubt anyone wants to make.

So, the main point is that a belief that ECMAScript has or is supposed to have 
a strict left-to-right evaluation order (as the concept is likely to be 
understood by typical users of the language) is wrong. For consistency, 
Dave-Sarah's observation that we first evaluate and then coerce the 
operands is probably the guideline we should continue to follow if we ever 
define any additional operators where the distinction is relevant.

allen

-Original Message-
From: es5-discuss-boun...@mozilla.org [mailto:es5-discuss-boun...@mozilla.org] 
On Behalf Of Oliver Hunt
Sent: Friday, November 20, 2009 5:07 PM
To: David-Sarah Hopwood
Cc: es5-disc...@mozilla.org
Subject: Re: ES5 left-to-right evaluation order issues

It was also observable through valueOf, toString, etc

--Oliver

On Nov 20, 2009, at 4:40 PM, David-Sarah Hopwood wrote:

 Allen Wirfs-Brock wrote:
 var o={get a() {alert(get a);return a}, get b() {alert (get b);return 
 b}};
 o.a*o.b;
 
 GetValue calls the accessor get functions, so based upon the above algorithm,
 you would expect to see the alert sequence: get a, get b, a valueOf,
 b valueOf.  This is exactly what happens for existing getter/setter
 implementations in at least FF and Chrome.
 
 I don't see a significant problem here. The arguments are still *evaluated*
 in left-to-right order. They're just not *coerced* at the same time as they
 are evaluated. But that was always the case in ES3; it hasn't changed in
 ES5. It's just a little bit more easily observable in ES5 because of
 getters.
 
 -- 
 David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com
 
 ___
 es5-discuss mailing list
 es5-disc...@mozilla.org
 https://mail.mozilla.org/listinfo/es5-discuss

___
es5-discuss mailing list
es5-disc...@mozilla.org
https://mail.mozilla.org/listinfo/es5-discuss
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: ES5 left-to-right evaluation order issues

2009-11-20 Thread David-Sarah Hopwood
Allen Wirfs-Brock wrote:
 This is good...Perhaps we should have a design rules section of the Wiki
to capture stuff like this?

I don't have edit rights to the wiki (the former ES4 wiki, that is, not
the Trac wiki), and AFAIK neither does anyone else who is not a member
of TC39.

 -Original Message-
 From: es5-discuss-boun...@mozilla.org 
 [mailto:es5-discuss-boun...@mozilla.org] On Behalf Of David-Sarah Hopwood
 Sent: Friday, November 20, 2009 7:18 PM
 To: es5-disc...@mozilla.org
 Subject: Re: ES5 left-to-right evaluation order issues
 
 Allen Wirfs-Brock wrote:
 So, the main point is that a belief that ECMAScript has or is supposed 
 to have a strict left-to-right evaluation order (as the concept is 
 likely to be understood by typical users of the language) is wrong.
 
 I'm going to have to insist that the understanding attributed to typical 
 users here is an improper understanding of evaluation and coercion in 
 general, and that ECMAScript *does* have left-to-right evaluation order.
 
 In most languages, the issue we're discussing here doesn't arise because if 
 there are implicit coercions, these coercions don't have side effects, and 
 therefore they don't have an observable ordering.
 
 However, in an imperative call-by-value language with left-to-right 
 evaluation where *individual operators* perform coercions with observable 
 side effects, the ECMAScript behaviour is precisely what should be expected.
 That's because the coercions are not part of the definition of evaluation; 
 they are specific to the computations performed by each operator.
 
 For example, the ECMAScript * operator behaves as though it were defined 
 something like the following function:
 
   function *(a, b) {
 return primitive_multiply(ToNumber(a), ToNumber(b));
   }
 
 Exactly as for a function application, the argument subexpressions are 
 evaluated, and then some computation is applied to the argument values.
 The coercions are performed, in order, as part of that computation.
 In fact, the coercions are different for each operator, so it is almost 
 essential that they be defined as part of the computation.
 
 If the change to coercion order that Allen originally suggested were made, 
 then it would be necessary to understand the evaluation of operator argument 
 subexpressions as being influenced by the operator and by the argument 
 position (for example, the shift operators coerce their left subexpression 
 with ToInt32 and their right subexpression with ToUint32), as opposed to 
 being uniform for all subexpressions. This is in some ways even weirder that 
 what ECMAScript currently does.
 
 It would also mean that if any future version of ECMAScript included operator 
 overloading, then either it would not be possible to precisely emulate the 
 semantics of the built-in versions of operators, or else the coercions would 
 have to be baked in and not overloadable (i.e. the overloading function 
 would have to receive its arguments pre-coerced, rather than being 
 responsible for coercing them). Either of these options are undesirable -- 
 the former would be inconsistent, and the latter less flexible and less 
 efficient, since it wouldn't be possible to drop the coercions.
 
 For consistency,
 Dave-Sarah's observation that we first evaluate and then coerce 
 the operands is probably the guideline we should continue to follow if 
 we ever define any additional operators where the distinction is relevant.
 
 Yes, also for the reasons above.
 
 --
 David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



signature.asc
Description: OpenPGP digital signature
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss