octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #58677] Error when using += operator


From: John W. Eaton
Subject: [Octave-bug-tracker] [bug #58677] Error when using += operator
Date: Tue, 30 Jun 2020 13:56:28 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0

Follow-up Comment #8, bug #58677 (project octave):

If you change the "x += 5" assignment to be "x = x + 5" it will work as you
expect.

The issue is that there is no ambiguity with "=" about whether the expression
is an assignment or can be a "command".  So if the parser sees "x = ..." it
tags X as a variable.  But, for compatibility with Matlab, we parse things
like "IDENT += ..." as commands unless IDENT is previously known to be a
variable.  In this case, because the script tb.m is parsed without knowledge
of the context in which it will be executed, the parser doesn't recognize X as
a variable.

In Rik's example from comment #7, the call to "whos" doesn't introduce X as a
variable when the script is parsed ("whos" could be overloaded to be something
other than the built-in "whos" function, so we can't expect the parser to
assume that the arguments will name variables).  However, the "whos" function
can look in the current stack frame at execution time to find the variable X.

I'm not sure what we can do to fix this issue unless we want to break
compatibility with Matlab when parsing command-style function calls.

Note that this issue is also not limited to Octave's "OP=" style assignment
operators.  The same issue can happen with scripts like this:


load x.mat  %% load a file that defines a variable "x"
x -option   %% error: x used as a variable and later as a function




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?58677>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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