[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #53871] In-place increment of a workspace vari
From: |
Richard Kirk |
Subject: |
[Octave-bug-tracker] [bug #53871] In-place increment of a workspace variable with += in a script issues error |
Date: |
Fri, 11 May 2018 05:15:27 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 |
Follow-up Comment #8, bug #53871 (project octave):
Following comment #5...
A more general statement would be...
The problem is when the var. is defined outside the script, then +=
incremented within a script.
If I understand things...
At parse time, the line...
count += 1;
..gets parsed using the command syntax as...
count ("+=", "1;")
...whereas the line...
count = 1;
..does not get parsed using the command syntax as...
count ("=", "1;")
..presumably due to some MatLab magic if the first argument begins with a
recognised assignment operator.
This is a bit weird. I would have been tempted to try parsing the line as an
expression, and then fall through to the command syntax if that fails.
However, as MatLab compatibility takes priority, we cannot change this special
case. In which case the bug changes to...
When the var. is defined outside the script, then += incremented within a
script, we get an obscure error message of the form...
error: count(61,_): but count has size 1x1
In cases where the first parsed argument is a valid Octave assignment that is
not supported in MatLab, we could suggest re-writing to assign using '=', or
to remove spaces between the var. name and the following operator.
There are some other quirky cases...
This works...
count+=1;
This is legal but does not work..
count ++;
..but this does..
count++;
It's all sort-of logical once you know what it is doing, but it is a bit of a
shock when you meet it for the first time. But there are lots of workarounds.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?53871>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #53871] Increment with += gives error in .m file, Richard Kirk, 2018/05/10
- [Octave-bug-tracker] [bug #53871] Increment with += gives error in .m file, John W. Eaton, 2018/05/10
- [Octave-bug-tracker] [bug #53871] Increment with += gives error in .m file, Richard Kirk, 2018/05/10
- [Octave-bug-tracker] [bug #53871] Increment with += gives error in .m file, John W. Eaton, 2018/05/10
- [Octave-bug-tracker] [bug #53871] Increment with += gives error in .m file, John W. Eaton, 2018/05/10
- [Octave-bug-tracker] [bug #53871] Increment with += gives error in .m file, Doug Stewart, 2018/05/10
- [Octave-bug-tracker] [bug #53871] In-place increment of a workspace variable with += in a script issues error, Rik, 2018/05/10
- [Octave-bug-tracker] [bug #53871] In-place increment of a workspace variable with += in a script issues error, Mike Miller, 2018/05/10
- [Octave-bug-tracker] [bug #53871] In-place increment of a workspace variable with += in a script issues error, Mike Miller, 2018/05/10
- [Octave-bug-tracker] [bug #53871] In-place increment of a workspace variable with += in a script issues error,
Richard Kirk <=
- [Octave-bug-tracker] [bug #53871] In-place increment of a workspace variable with += in a script issues error, Richard Kirk, 2018/05/12