[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expr
From: |
Philip Nienhuis |
Subject: |
[Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression |
Date: |
Sat, 11 Aug 2018 18:12:54 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0 SeaMonkey/2.48 |
Follow-up Comment #3, bug #54490 (project octave):
First 5 lines as a function bug54490.m file in Matlab r2018b:
>> edit bug54490a.m
>> clear
>> global k;
disp("Testing simple assignment:")
k = 2;
a = [5 6];
Testing simple assignment:
>> a(k) = bug54490a();
>> a
a =
3 6
>> disp("Testing multiple assignment:")
k = 2;
a = [5 6];
[a(k)] = bug54490a()
Testing multiple assignment:
a =
3 6
>>
Octave-5.0.0:
>> clear
>> function out=bug54490a
global k;
k = 1;
out = 3;
end
>> global k;
>> disp("Testing simple assignment:")
Testing simple assignment:
>> k = 2;
>> a = [5 6];
>> a(k) = bug54490a();
>> a
a =
3 6
>> # result : a = [3 6]
>> disp("Testing multiple assignment:")
Testing multiple assignment:
>> k = 2;
>> a = [5 6];
>> [a(k)] = bug54490a();
>> a
a =
5 3
... so indeed Octave's behavior differs from Matlab's.
It is unclear to me what you mean exactly with "multiple assignment". AFAICS
the only difference is that output from the function in the "multiple
assignment" case is between brackets, but there's still just one variable
(i.e., a).
To me it looks more like global variable k's new value from inside the
function call is conveyed outside the function only after the square brackets
have been processed; i.e., a sort of timing issue rather than evaluation order
issue.
After the statement k equals 1 as it should but experimenting with values of
before the function call shows that it still has the old value at the time of
assignment of the function output to the output variable a.
I'll cc JWE who has the most knowledge of the parser.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?54490>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, anonymous, 2018/08/11
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, Philip Nienhuis, 2018/08/11
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, anonymous, 2018/08/11
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression,
Philip Nienhuis <=
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, Philip Nienhuis, 2018/08/11
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, anonymous, 2018/08/11
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, Philip Nienhuis, 2018/08/12
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, Guillaume, 2018/08/13
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, John W. Eaton, 2018/08/13
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, John W. Eaton, 2018/08/13
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, John W. Eaton, 2018/08/14
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, Philip Nienhuis, 2018/08/17
- [Octave-bug-tracker] [bug #54490] Order of evaluation in assignment expression, Rik, 2018/08/27