Re: assignment: left-to-right or right-to-left evaluation?

2009-06-21 Thread Sergey Gromov
Sat, 09 May 2009 11:43:09 -0500, Andrei Alexandrescu wrote: If we want to get rid of newID, we'd write: writeln(dic.length, '\t', word); dic[word] = dic.length; by the Python rule, and writeln(dic.length, '\t', word); dic[word] = dic.length - 1; by the

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-16 Thread Christopher Wright
Georg Wrede wrote: bearophile wrote: Georg Wrede: arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such dependences are good code. By stating a definite order between lvalue and rvalue, you would actually encourage this kind of code. I agree that putting such things in code is

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-16 Thread Andrei Alexandrescu
Christopher Wright wrote: Georg Wrede wrote: bearophile wrote: Georg Wrede: arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such dependences are good code. By stating a definite order between lvalue and rvalue, you would actually encourage this kind of code. I agree that

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-16 Thread Georg Wrede
Andrei Alexandrescu wrote: Christopher Wright wrote: Georg Wrede wrote: bearophile wrote: Georg Wrede: arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such dependences are good code. By stating a definite order between lvalue and rvalue, you would actually encourage this kind of

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-15 Thread bearophile
Georg Wrede: arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such dependences are good code. By stating a definite order between lvalue and rvalue, you would actually encourage this kind of code. I agree that putting such things in code is bad, but nowadays the solution adopted

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-15 Thread Georg Wrede
bearophile wrote: Georg Wrede: arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such dependences are good code. By stating a definite order between lvalue and rvalue, you would actually encourage this kind of code. I agree that putting such things in code is bad, but nowadays the

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-15 Thread bearophile
Georg Wrede: If Walter had ulimited time, the of course I'd favor either defining the precedence, or then enforcing errors on them, and not leaving them undefined. Or, probably, with Walter's unlimited time, I'd vote for a system that is the Theoretically Best mix of programming praxis and

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-15 Thread Andrei Alexandrescu
bearophile wrote: Georg Wrede: arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such dependences are good code. By stating a definite order between lvalue and rvalue, you would actually encourage this kind of code. I agree that putting such things in code is bad, but nowadays the

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-12 Thread Michiel Helvensteijn
Jarrett Billingsley wrote: It's incredibly rare that I have to assign the same value to multiple targets, and when I do, the little time I could save by not typing the second assignment is offset by the increased time it takes me to look for assignments to a variable when I come back to the

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-12 Thread Christopher Wright
Michiel Helvensteijn wrote: Jarrett Billingsley wrote: It's incredibly rare that I have to assign the same value to multiple targets, and when I do, the little time I could save by not typing the second assignment is offset by the increased time it takes me to look for assignments to a

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-12 Thread Kagamin
Well, seems like disambiguation will solve only portability issues. From performance point of view in order to call int opIndexAssign(int value, size_t i) you should fisrt evaluate value, then indexes.

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Georg Wrede
Andrei Alexandrescu wrote: Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such dependences are good code. By stating a definite order between lvalue and

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Michel Fortin
On 2009-05-11 05:49:01 -0400, Georg Wrede georg.wr...@iki.fi said: Andrei Alexandrescu wrote: Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Steven Schveighoffer
On Sat, 09 May 2009 19:15:59 -0400, Derek Parnell de...@psych.ward wrote: On Sat, 09 May 2009 11:43:09 -0500, Andrei Alexandrescu wrote: Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? It's a rather arbitrary

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Steven Schveighoffer
On Mon, 11 May 2009 07:34:38 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: For example: mydic[x] = mydic[y] = mydic[z] = mydic.length; if evaluating right to left, this looks like: 1. calculate mydic.length, store it in register A. 2. lookup mydic[z], if it doesn't exist, add it.

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Manfred Nowak
Michel Fortin wrote: arra[i++] = arrb[j]; // how can the compiler issue an error for this? assert( i != j); -manfred

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Michiel Helvensteijn
Consider that mathematically speaking, an array is a function. And an assignment to an array element actually changes the function. A[i] = E; is actually the same as A = A[E/i];, where the right-hand side reads: A where i yields E (notation not to be confused with division). It is formally

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Georg Wrede
Jason House wrote: Michel Fortin Wrote: On 2009-05-11 05:49:01 -0400, Georg Wrede georg.wr...@iki.fi said: Andrei Alexandrescu wrote: Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? arra[i] = arrb[i++]; arra[i++]

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Andrei Alexandrescu
Steven Schveighoffer wrote: On Mon, 11 May 2009 08:20:07 -0400, Manfred Nowak svv1...@hotmail.com wrote: Michel Fortin wrote: arra[i++] = arrb[j]; // how can the compiler issue an error for this? assert( i != j); -manfred That is not a compiler error, it is an

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Georg Wrede
Steven Schveighoffer wrote: For example: mydic[x] = mydic[y] = mydic[z] = mydic.length; I distinctly remember Walter discouraging chained assignments in the doccs, already in the very early versions of D.

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Steven Schveighoffer
On Mon, 11 May 2009 09:37:56 -0400, Georg Wrede georg.wr...@iki.fi wrote: Steven Schveighoffer wrote: For example: mydic[x] = mydic[y] = mydic[z] = mydic.length; I distinctly remember Walter discouraging chained assignments in the doccs, already in the very early versions of D.

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Jarrett Billingsley
On Mon, May 11, 2009 at 11:07 AM, Steven Schveighoffer schvei...@yahoo.com wrote:  mydic[x] = mydic[y] = mydic[z] = mydic.length; auto tmp = mydic.length; mydic[x] = tmp; mydic[y] = tmp; mydic[z] = tmp; ??? That sucks.  We have to remember, there are reasons why we stopped having to

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Steven Schveighoffer
On Mon, 11 May 2009 11:26:36 -0400, Jarrett Billingsley jarrett.billings...@gmail.com wrote: On Mon, May 11, 2009 at 11:07 AM, Steven Schveighoffer schvei...@yahoo.com wrote:  mydic[x] = mydic[y] = mydic[z] = mydic.length; auto tmp = mydic.length; mydic[x] = tmp; mydic[y] = tmp; mydic[z]

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Georg Wrede
Andrei Alexandrescu wrote: Georg Wrede wrote: Andrei Alexandrescu wrote: Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? arra[i] = arrb[i++]; arra[i++] = arrb[i]; I'm not sure that such dependences are good code.

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Andrei Alexandrescu
Georg Wrede wrote: If the programmer has introduced dependencies on the evaluation order, yes. But if he hasn't, then it will not introduce anything. If violations could be checked such that invalid code is rejected, your solution would work. With a[fun] = gun; a rewrite auto f =

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Georg Wrede
Andrei Alexandrescu wrote: Georg Wrede wrote: If the programmer has introduced dependencies on the evaluation order, yes. But if he hasn't, then it will not introduce anything. If violations could be checked such that invalid code is rejected, your solution would work. With a[fun] =

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Nick Sabalausky
Steven Schveighoffer schvei...@yahoo.com wrote in message news:op.utrtl8x7eav...@steves.networkengines.com... On Mon, 11 May 2009 09:37:56 -0400, Georg Wrede georg.wr...@iki.fi wrote: Steven Schveighoffer wrote: For example: mydic[x] = mydic[y] = mydic[z] = mydic.length; I distinctly

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Michiel Helvensteijn
Nick Sabalausky wrote: I was giving a little bit of thought to assignment chaining the other day. Unless someone can point out why I'm wrong, I think some of the functional-style stuff we've been getting into can make assignment chaining obsolete. Hypothetical example: [mydic[x],

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Nick Sabalausky
Michiel Helvensteijn m.helvensteijn.rem...@gmail.com wrote in message news:gua0ub$130...@digitalmars.com... Nick Sabalausky wrote: I was giving a little bit of thought to assignment chaining the other day. Unless someone can point out why I'm wrong, I think some of the functional-style

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Derek Parnell
On Mon, 11 May 2009 16:03:39 -0400, Nick Sabalausky wrote: I was giving a little bit of thought to assignment chaining the other day. Unless someone can point out why I'm wrong, I think some of the functional-style stuff we've been getting into can make assignment chaining obsolete.

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Rainer Deyke
Nick Sabalausky wrote: True, that's why I replied again and suggested something like: [mydic[x], mydic[y], mydic[z]].each = mydic.length; [[mydic[x], mydic[y], mydic[z]].each].each = mydic.length; [[[mydic[x], mydic[y], mydic[z]].each].each].each = mydic.length; mydic[x], mydic[y],

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Nick Sabalausky
Rainer Deyke rain...@eldwood.com wrote in message news:guamfi$2b0...@digitalmars.com... Nick Sabalausky wrote: True, that's why I replied again and suggested something like: [mydic[x], mydic[y], mydic[z]].each = mydic.length; [[mydic[x], mydic[y], mydic[z]].each].each = mydic.length;

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Rainer Deyke
Nick Sabalausky wrote: Rainer Deyke rain...@eldwood.com wrote in message news:guamfi$2b0...@digitalmars.com... [[mydic[x], mydic[y], mydic[z]].each].each = mydic.length; ... I'm not sure what point you're trying to make here, but my idea is that each would basically be a write-only

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-11 Thread Jarrett Billingsley
On Mon, May 11, 2009 at 11:34 AM, Steven Schveighoffer schvei...@yahoo.com wrote: Funny, I vastly prefer the latter to the former.  Having more than one thing happen on one line is very difficult to read after having written it, for me. So I take it if you have many function calls, or

assignment: left-to-right or right-to-left evaluation?

2009-05-09 Thread Andrei Alexandrescu
Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? It's a rather arbitrary decision. C/C++ don't even define an order. Python chooses left-to-right, EXCEPT for assignment, which is right-hand side first. Lisp and C#

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-09 Thread Frank Benoit
Andrei Alexandrescu schrieb: Consider: uint fun(); int gun(); int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? It's a rather arbitrary decision. C/C++ don't even define an order. Python chooses left-to-right, EXCEPT for assignment, which is

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-09 Thread Andrei Alexandrescu
Frank Benoit wrote: From my POV, it would be nice if it would be the same as in Java, because i am porting lots of it to D. Good point. I searched for that one and found: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html The Java programming language guarantees that

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-09 Thread Jarrett Billingsley
On Sat, May 9, 2009 at 1:52 PM, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: I also searched for the way Perl does it and got a tad disappointed: http://www.nntp.perl.org/group/perl.perl5.porters/2003/09/msg82032.html Essentially the order of evaluation in Perl is as arbitrary

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-09 Thread Michiel Helvensteijn
Andrei Alexandrescu wrote: Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? It's a rather arbitrary decision. C/C++ don't even define an order. Python chooses left-to-right, EXCEPT for assignment, which is

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-09 Thread Nick Sabalausky
Andrei Alexandrescu seewebsiteforem...@erdani.org wrote in message news:gu4bqu$b...@digitalmars.com... Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? It's a rather arbitrary decision. C/C++ don't even define an

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-09 Thread Frank Benoit
Andrei Alexandrescu schrieb: Frank Benoit wrote: From my POV, it would be nice if it would be the same as in Java, because i am porting lots of it to D. Good point. I searched for that one and found: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html The Java

Re: assignment: left-to-right or right-to-left evaluation?

2009-05-09 Thread Derek Parnell
On Sat, 09 May 2009 11:43:09 -0500, Andrei Alexandrescu wrote: Consider: uint fun(); int gun(); ... int[] a = new int[5]; a[fun] = gun; Which should be evaluated first, fun() or gun()? It's a rather arbitrary decision. C/C++ don't even define an order. Python chooses left-to-right,