[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #62552] In-place operator spacing works for 'i
From: |
Nicholas Jankowski |
Subject: |
[Octave-bug-tracker] [bug #62552] In-place operator spacing works for 'i' and 'j', but not other variable names |
Date: |
Mon, 5 Dec 2022 16:29:28 -0500 (EST) |
Update of bug #62552 (project octave):
Status: Confirmed => Patch Submitted
_______________________________________________________
Follow-up Comment #44:
Realized i let this sit for a month. here's my proposed addition to the
Command-Syntax-and-Function-Syntax section of func.txi trying to explain the
current state of Octave deciding between command and function syntax with
operator/whitespace ambiguity.
I also added a small note in expr.txi (Arithmetic Operators) noting the
potential ambiguity and linking to the Command Syntax section. Could probably
also add a similar note under Comparison and Boolean sections, but that seems
a bit redundant.
Could use someone to review and verify both my texinfo and my terminology
(statements/expressions/symbols, etc.) are correct.
Should apply clean to either stable or default, but would be nice to get this
into the 8 docs since these changes are somewhat new.
here are the text blocks below:
func.txi:
It should be noted that mixing command syntax and binary operators can
create ambiguities with mathematical and logical expressions that would use
function syntax. For example, all three of the statements
@example
arg1 - arg2
arg1 -arg2
arg1-arg2
@end example
@noindent
could be interpreted as a subtraction operation between
@code{arg1} and @code{arg2}. The first two, however, could also e taken as a
command syntax call to function @code{arg1}, in the first case with options
@code{-} and @code{arg2}, and in the second case with option code{-arg2}.
Octave uses whitespace to interpret such expressions according to the
following rules:
@itemize @bullet
@item
Statements consisting of plain symbols without any operators that are
separated only by whitespace are always treated as command syntax:
@example
arg1 arg2 arg3 ... argn
@end example
@item
Statements without any whitespace are always treated as function syntax:
@example
arg1+arg2
arg1&&arg2||arg3
arg1+=arg2*arg3
@end example
@item
If the first symbol is a constant (or special-valued named constant pi, i, I,
j, J, e, NaN, or Inf) followed by a binary operator, the statement is treated
as function syntax regardless of any whitespace or what follows the second
symbol:
@example
7 -arg2
pi+ arg2
j * arg2 -arg3
@end example
@item
If the first symbol is a function or variable and there is no whitespace
separating the operator and the second symbol, the statement is treated
as command syntax:
@example
arg1 -arg2
arg1 &&arg2 ||arg3
arg1 +=arg2*arg3
@end example
@item
Any other whitespace combination will result in the statement being treated
as function syntax.
@end itemize
Note 1: If a special-valued named constant has been redefined as a
variable, the interpreter will still process the statement with
function syntax.
Note 2: Attempting to use a variable as @code{arg1} in a command being
processed as command syntax will result in an error.
expr.txi:
Note also that some combinations of binary operators and whitespace can
create ambiguities with Octave's Command Syntax form of calling functions.
See
@ref{Command Syntax and Function Syntax} for more detail on avoiding such
issues.
(file #54059)
_______________________________________________________
Additional Item Attachment:
File name: doc_commandsyntax_operators_bug62552.patch Size:4 KB
<https://file.savannah.gnu.org/file/doc_commandsyntax_operators_bug62552.patch?file_id=54059>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?62552>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #62552] In-place operator spacing works for 'i' and 'j', but not other variable names,
Nicholas Jankowski <=