help-octave
[Top][All Lists]
Advanced

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

Re: conditional expr operator in Octave?


From: John W. Eaton
Subject: Re: conditional expr operator in Octave?
Date: Fri, 7 Aug 2009 14:03:25 -0400

On 30-Jul-2009, Jaroslav Hajek wrote:

| On Thu, Jul 30, 2009 at 8:49 PM, John W. Eaton<address@hidden> wrote:
| > On 30-Jul-2009, Jaroslav Hajek wrote:
| >
| > | OK, I'm dropping it; instead, I implemented the "merge" function aka
| > | Fortran 90 (which I needed for some time) and slightly extended the
| > | scalar mask case to allow arbitrary (even non-array) values.
| > | http://hg.savannah.gnu.org/hgweb/octave/rev/833109a9f37f
| > |
| > | merge (mask, tval, fval)
| > | can now be used instead of mask ? tval : fval (except that it does not
| > | short-circuit).
| >
| > The name "merge" doesn't seem very intuitive to me.  What about using
| > "ifelse" instead?
| >
| 
| I borrowed the name from Fortran 90. It makes sense if you think of
| the array usage: it merges the two arrays, tval and fval, according to
| mask. I just realized that this function can actually be used instead
| of the conditional operator.
| I have no problem calling it ifelse instead, but merge also makes good
| sense. OTOH, "ifelse" is probably less likely to clash with anything
| else ("merge" can suit many functions), so perhaps it is a better
| name.

Yes, I was thinking about the scalar case when I suggested ifelse.
Thinking about how it works for vectors, I can understand why merge is
an appropriate name.  And, given the way the function actually works,
ifelse could be misleading.  For example, I would think of

  ifelse (COND, X, Y)

returning X if COND is true in an overall sense (like the condition of
an IF statement), and Y if it is false.  So maybe merge is the better
name.

jwe



reply via email to

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