On Jun 11, 9:10 am, [EMAIL PROTECTED] (Jonathan Lang) wrote:
> Rereading A03, I ran across the original reasoning behind why Perl 5's
> '?:' trinary operator became '?? ::' first, and then '?? !!'.  Three
> reasons were given:
>
> * the '?' and ':' tokens are far too broadly useful to be gobbled up
> by the trinary operator.
>
> * the doubled symbols bring to mind the short-circuiting operators
> (e.g., '&&' and '||'), suggesting a similar short-circuiting behavior
> here.
>
> * the '!!' brings to mind "evaluate this when the condition fails".
>
> IMHO, the first point was always more about the ':' than it was about
> the '?'; if you were to replace ':' with '!', I suspect that this
> concern would largely go away.  That is, I don't see any infix:<?> or
> infix:<!> operators in the current draft.  A case could be made that a
> trinary '... ? ... ! ...' operator could work within the current state
> of things without conflict.  Also, the whitespace disambiguation rules
> that were later implemented go a long way to resolving the original
> problem of ':' trying to do too much.
>
> That said, the latter two points are still valid.  '... ? ... : ...'
> might be perfectly workable; but so is '... ?? ... !! ...'.
>
> However, there still may be room for improvement.  Consider the
> following possibility:
>
> Instead of being a single, inflexible trinary operator, break this
> into a pair of binary operators: infix:<??> and infix:<!!>.  Each can
> be used on its own, returning the right side if the condition
> evaluates as expected (i.e., true for ?? and false for !!), and
> otherwise returns 'undef'.  A variation of chaining associativity gets
> used, with the "chaining rule" being '$v1 op1 $v2 // $v1 op2 $v3'
> instead of '$v1 op1 $v2 && $v2 op2 $v3', as is the case for comparison
> chaining.  So all of the following would be valid syntax:
>
>   $test ?? $a !! $b  # true: $a; false: $b
>   $test !! $a ?? $b  # true: $b; false: $a
>   $test ?? $a       # true: $a; false: undef
>   $test !! $b       # true: undef; false: $a
>
> I suggest this mainly because it's potentially more extensible than
> the current model.  I could see someone devising a "fuzzy logic"
> module which could allow for such things as:
>
>   $test ?? $a !! $b maybe $c likely $d unlikely $e
>
> --
> Jonathan "Dataweaver" Lang

Surely if you defined !! to return "undef but true" and both operators
to be left associative then it all works.

 1==0 ?? "True" !! "False" -> (undef) !! "False" which seems right to
me.

 1==1 !! "False" ?? "True" -> (undef but true) ?? "True" also good.

TTFN, Struan

Reply via email to