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

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

[Octave-bug-tracker] [bug #51045] ?: ternary operator


From: Ernst Reissner
Subject: [Octave-bug-tracker] [bug #51045] ?: ternary operator
Date: Tue, 16 May 2017 19:15:13 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0

URL:
  <http://savannah.gnu.org/bugs/?51045>

                 Summary: ?: ternary operator
                 Project: GNU Octave
            Submitted by: ernstreissner
            Submitted on: Tue 16 May 2017 11:15:11 PM UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Feature Request
                  Status: None
             Assigned to: None
         Originator Name: ernstreissner
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: Any

    _______________________________________________________

Details:

This is not really a feature request but a request for discussion: 
In C there is a ternary operator: 
a ? b : c 
with a boolean and b and c the same but arbitrary type. 
If a is true this evaluates to b else to c. 

pro implementing this: 
It is convenient and octave already has a lot of stuff 
loaned from C. 

contra implementing this: 
It is another operator not present in matlab. 

Another very subtile advantage: 
logical operators & and | can be overwritten for objects 
whereas for && and || this is (almost) impossible. 
i have the case that I provide a logical type with oo means. 
With the ?: ternary operator 
I could write (a little simplified but just to show the idea) 
bool(a) ? true : b with a, b of my own logical type 
which is equivalent with a&&b. 

Of course it is possible to do the same with if: 
if bool(a); x=true else x=b; end
but this requires an additional auxiliary variable x. 





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51045>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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