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:
Eric Brine
Date:
October 13, 2015 00:53
Subject:
Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]
Message ID:
CALJW-qFg7dQJaR_onj9t_72wSPLvp1SNpihuOd0PY1ws5p2EMA@mail.gmail.com
On Mon, Oct 12, 2015 at 8:08 PM, Abigail <abigail@abigail.be> wrote:

> So, 'use bigint' is something funky?
>

No, "==" works fine with numbers replaced by "use bigint;".


> But if it turns out that we're still left with something which requires
> you to know what Perl does at compile time


I lost you there. Why do you say that?


> and it won't play nice with modules that do constant overloading


Do you have an example of a module that overrides numerical constants such
that "==" doesn't work?


> Perhaps we should admit defeat, and just accept that in Perl, it's
> operator that determines the type of the argument(s), and not the
> type of the argument(s) which determines the operation. Hence, different
> named "when"s, one for each type of match. (This has already been
> suggested by others).
>

To be clear, I don't have a problem with either approach.

Bike-shedding:
>
>      when:def         {...}      # !defined $_
>      when:num (3)     {...}      # $_ == 3
>      when:str ("foo") {...}      # $_ eq "foo"
>      when:pat (/bar/) {...}      # /bar/
>
>      when:num (3, 4, 5)       {...}    # $x = $_; grep {$_ == $x} 3, 4, 5
>      when:str ("a", "b", "c") {...}    # $x = $_; grep {$_ eq $x} "a",
> "b", "c"
>

I'd add a way of doing an arbitrary boolean expression. Maybe "when" with
no attribute?  e.g. when ($_ == 3)

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