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

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

Thread Next
From:
Ricardo Signes
Date:
September 14, 2012 08:14
Subject:
given/when/~~ "final" thoughts (ha ha ha)
Message ID:
20120914151442.GA31686@cancer.codesimply.com

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
statement:

  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.

-- 
rjbs


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