develooper Front page | perl.perl5.porters | Postings from October 2015

Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]

Thread Previous | Thread Next
From:
Ricardo Signes
Date:
October 19, 2015 02:58
Subject:
Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]
Message ID:
20151019025847.GE18956@cancer.codesimply.com
* Abigail <abigail@abigail.be> [2015-10-12T20:08:20]
> Bike-shedding:
> 
>      when:def         {...}      # !defined $_
>      when:num (3)     {...}      # $_ == 3
>      when:str ("foo") {...}      # $_ eq "foo"
>      when:pat (/bar/) {...}      # /bar/

compare:

  when (num(3))     { ... }
  when (str("foo")) { ... }

This gets you the same behavior, but leaves the test value as a thing that can
be used as the rhs of a match, which means it can be passed around as a first
class predicate value.

The downside is that given a currently possible implementation of &num, it
would do a lot more work than being compiled down to an == operation in the op
tree.

On the other hand, a future &num could provide a faster magic value that ~~'s
implementation can know to directly resolve to a numeric comparison.  I'd doubt
it would ever match custom when:num syntax in speed, but I think it is much
more generically useful because it enables tests to be arguments rather than
only in-place parts of the program source.

-- 
rjbs

Thread Previous | 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