[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

a=0; a([1,1])++ -> a == 2

From: John W. Eaton
Subject: a=0; a([1,1])++ -> a == 2
Date: Wed, 2 Aug 2000 13:51:01 -0500 (CDT)

On  2-Aug-2000, Etienne Grossmann <address@hidden> wrote:

|   sorry if the answer to my question is a clear-cut "no" or if it has
| already been discussed.
|   Wouldn't it make sense to have the code 
|        a=0; b = a([1,1])++ ;
|   be equivalent to either
|        a=0; b=a([1,1]); b++; for i in [1,1], a(i)++ ; end
|        yielding       a == 2, b == [1;1]

Hmm.  I can agree with what is inside the loop, but not the b++ that
is outside.  The way a statement like

  b = a([1,1])++

is evaluated requires that the operation on the right hand side
produce a value, and then that result is copied to the left hand side
of the assignment.  So, what should the value of a([1,1])++ be?  Since
a([1,1]) references the same location twice, I suppose it is
reasonable to think that it should increment twice, but it also seems
reasonable that it should only increment once, since you have one `++'
operator operating on one location.  It also makes sense when you
think about it this way:

  a = 0; a([1,1])++

is equivalent to

  a = 0; t = a([1,1]); a([1,1]) += 1; t


  a = 0; t = a([1,1]); a([1,1]) = a([1,1]) + 1; t

With the value of the expression being `t'.

|   or 
|        a=0; b=zeros(size(a)); for i in [1,1], b(i) = a(i)++ ; end
|        yielding       a == 2, b == [1;2]

I don't think this is the correct interpretation of what this code
would currently do in Octave.  With my current sources (approximately
the same as the latest 2.1.x release), I see

  octave:11> a=0; b=zeros(size(a)); for i = [1,1], b(i) = a(i)++ ; end, a, b
  a = 2
  b = 1

|   The current behavior yields :
|       a == 1, b == [1;1]

Hmm.  Not what I see:

  octave:9> a=0; b = a([1,1])++; a, b 
  a = 1
  b =

    0  0

Are you using some different version of Octave that behaves


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]