develooper Front page | perl.perl6.language | Postings from September 2005

Proposal: split ternary ?? :: into binary ?? and //

Thread Next
Thomas Sandlass
September 5, 2005 05:39
Proposal: split ternary ?? :: into binary ?? and //
Message ID:

I'm still contemplating how to get rid of the :: in the
ternary and make :: unequivocally available for a type
sigil and as a binary infix for symbol lookup. 

Here's a possible solution:

1) ?? becomes a binary operator that behaves as follows:
   a) it evaluates its lhs in boolean context
   b) if this is true, ?? evaluates its rhs such that it
      can't be undef
   c) if this is false, ?? returns undef

2) the precedence of ?? is above // which naturally catches
   the undef of a false condition.

This gives

   $x = $y < 3 ?? "small" // "large";

and possibly even a low precedence version

   $x = $y < 3 then      "small" err "large";  # hmm
               thence                          # old fashioned
               therefore                       # long, but clear

An implementation could read:

&*infix:<??> (&cond, &code)
  is parsed(...) # trait needed to insert {}?
   if &cond() { return &code() but defined }
   else       { return undef }



Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About