bugGNU Octave - Bugs: bug #52016, '&' or '|' used in until...

 
 

bug #52016: '&' or '|' used in until condition should warn about short-circuiting

Submitter:  Ernst Reissner <ernstreissner>
Submitted:  Thu 14 Sep 2017 09:33:18 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Feature Request
Status:  Confirmed Assigned to:  None
Originator Name:  ernstreissner Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 15 Sep 2017 05:57:00 PM UTC, comment #6: 

I don't venture in to the parser and tree evaluation code much so I can't comment.  But, if this is going to be complex then it should perhaps be reduced in priority.

Rik <rik5>
Group administrator
Fri 15 Sep 2017 05:45:29 PM UTC, comment #5: 

This is a little more complicated than adding a warning in the right place. The parser will have to mark the conditional expression in an 'until' with a new flag, as a loop condition expression that is not braindead, just so the evaluator can see if the & or | operators are used in the conditional expression and issue a new warning message. Something like "warning: Matlab-style short-circuit operation not performed for operator |"?

Mike Miller <mtmiller>
Group Member
Thu 14 Sep 2017 04:15:39 PM UTC, comment #4: 

A warning is fine with me.  Re-titling report.

Rik <rik5>
Group administrator
Thu 14 Sep 2017 04:07:27 PM UTC, comment #3: 

I'm OK with adding a warning if the conditions for Matlab short-circuiting occur in the condition of an UNTIL statement, but I don't want to change the behavior of UNTIL statements to do that kind of short circuiting.  It's not needed for compatibility since Matlab doesn't have this statement.

John W. Eaton <jwe>
Group administrator
Thu 14 Sep 2017 03:54:17 PM UTC, comment #2: 

Sholdn't the short-circuit warning be extended to cover the 'until' condition?  If a programmer is migrating from Matlab to Octave they may decide to use do/until loops, but with the assumption that the condition works the same as a while loop.

In other words, I don't think we should have different behaviors based on keyword used for the looping structure.  It becomes a difficulty to remember which loop does which thing.  Instead, they should all behave similarly, although Octave gives you more choices.

Rik <rik5>
Group administrator
Thu 14 Sep 2017 09:43:08 AM UTC, comment #1: 

There is another place in the manual also: Section 8.5.2:

matlab has special behavior that allows the operators ‘&’ and ‘|’ to short-circuit when
used in the truth expression for if and while statements. Octave behaves the same way for
compatibility, however, the use of the ‘&’ and ‘|’ operators in this way is strongly discouraged
and a warning will be issued. Instead, you should use the ‘&&’ and ‘||’ operators that always
have short-circuit behavior.


One could mention until also:
As matlab does not support until-statement,
in octave, & and | behave regularly in until-conditions.

Also a reference to the warning would be fine.

Ernst Reissner <ernstreissner>
Thu 14 Sep 2017 09:33:18 AM UTC, original submission:  

In the manual page 228 or around, we read:

If the Octave:possible-matlab-short-circuit-operator warning is
enabled, Octave will warn about using the not short circuiting operators &
and | inside if or while conditions.


I feel, one should mention that this warning
is to make clear, that in if and while conditions
& and | behave like && and || and shall thus be replaced by
explictly && and ||.
This is for matlab compatibility.
As matlab does not support until statements,
octave treats & and | in until conditions
regularly without shortcut.

Ernst Reissner <ernstreissner>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by ernstreissner (Submitted the item)
  • -email is unavailable- added by ernstreissner
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-22 mtmiller Carbon-CopyRemoved 80942 -
    2017-09-14 rik5 CategoryDocumentation Interpreter
        Item GroupDocumentation Feature Request
    2017-09-14 rik5 Summaryconversion to short circuit in if, while but not in until '&' or '|' used in until condition should warn about short-circuiting
    2017-09-14 rik5 StatusNone Confirmed
    2017-09-14 ernstreissner Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code