develooper Front page | perl.perl5.porters | Postings from September 2012

given/when/~~ "final" thoughts (ha ha ha)

Thread Next
Ricardo Signes
September 14, 2012 08:14
given/when/~~ "final" thoughts (ha ha ha)
Message ID:

The last thing I'd said about smartmatch was:

  $x ~~ undef                                                                   
  $x ~~ $overloaded_object                                                      
  $x ~~ sub {}                                                                  
  $x ~~ regex                                                                   
  ...or fail                                                                    

...with when:

  when ("foo") # str eq
  when (12345) # num ==
  when ($x)    # ~~
  when { ... } # block evaluates true

  when breaks the enclosing topicalizer

I wanted to post that this is a design that would get accepted.  The
reservation of the final case, rather than eq/==, in smart match, lets us
figure out whether future work on improving num-v-str can be put to work here.

On the other hand, there's plenty of reason to give upon given/when/~~, too,
and I think that the one thing we might keep using would be a when-like

  case (EXPR) BLOCK

equivalent to:

  if ($EXPR) { BLOCK <next unless continue> }

That would be a reasonable thing to keep around if we decide we can't get to an
acceptable smartmatching future.

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