[macstl-dev] IIf function -- opinions wanted

Glen Low glen.low at pixelglow.com
Sat Mar 12 16:11:35 WST 2005

  • Previous message: [macstl-dev] IIf function -- opinions wanted
  • Next message: [macstl-dev] IIf function -- opinions wanted
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]


On 09/03/2005, at 9:30 AM, Holger Bettag wrote:

> On Wed, 9 Mar 2005, Glen Low wrote:
>
>> 1.	iif -- inspired by Visual Basic, somewhat terse though.
>> 2.	if_then -- seen this in Boost Lambda. However so far nothing in the
>> common interface has an underscore, so far.
>> 3.	if_then_else -- more explicit what it does
>> 4.	sel or select -- show its similarity to vec_sel, however may be
>> confusing as vec_sel (and thus altivec::sel) has a different order of
>> parameters.
>> 5.	cond or condition -- doesn't read off as easily
>>
> AFAIK 'select' is the usual name for this type of operation. A
> 'conditional move' would be something else, and 'if then else' changes
> control flow rather than data flow.
>

Andrew has the same opinion as you.

However, I'm worried about the ease of mistyping and argument order. If 
we follow the VB iif and C++ ternary operator standard and "natural" 
argument placement, then it is different from Altivec's vec_sel and it 
might be too easy for a programmer to mistype it.

select (if_part, then_part, else_part); // this would be in the common 
interface
sel (else_part, then_part, if_part); // this would be in the Altivec 
platform interface, corresponding to vec_sel

As I see it, there are two solutions:

1.	Give the common interface function some other name, or at least not 
a proper superset of sel.
2.	Let the common interface function have the same argument order as 
Altivec sel.

I'm rather partial to iif, although that and any variant that includes 
"if" in it may carry the false sense that a control flow is meant (as 
you said) i.e. that if_part is a boolean and either then_part or 
else_part is entirely selected and/or the other is not evaluated 
[control flow], rather than selecting elements of then_part and 
elements of else_part according to the elements of if_part [data flow]. 
Then again, && and || now operate on valarray and vec with data flow, 
even though the original meanings in C++ were control flow.

I haven't been able to google out any other direct equivalents in other 
languages. It seems all the C descendants went for "if_part ? then_part 
: else_part", and all the Basic descendants and variants went for "iif 
(if_part, then_part, else_part)". Python seems to have an even stranger 
"if_part and then_part or else_part". Don't see any other "conditional 
select" data flow variants except Altivec's vec_sel.

The minor danger with iif is that Microsoft will go and patent it, just 
like they did with AndNot :-)

Further opinions, especially from the non-Altivec users here?


Cheers, Glen Low


---
pixelglow software | simply brilliant stuff
www.pixelglow.com




  • Previous message: [macstl-dev] IIf function -- opinions wanted
  • Next message: [macstl-dev] IIf function -- opinions wanted
  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

More information about the macstl-dev mailing list