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

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

Thread Next
From:
Thomas Sandlass
Date:
September 5, 2005 05:39
Subject:
Proposal: split ternary ?? :: into binary ?? and //
Message ID:
8B2D97A317E8C9479E35FED99ADC3096CCC8C3@br2mex01.orthogon.com
HaloO,

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 }
}


Comments?

TSa


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About