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

Re: fixing smartmatch just hard enough (and when, too)

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
August 31, 2012 02:24
Subject:
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
CAHAeAG472Fx86cEOu+S=QFAeNOj=-4DkVjOTbNk5K8KqgpL_ew@mail.gmail.com
On Fri, Aug 31, 2012 at 9:48 AM, Johan Vromans <jvromans@squirrel.nl> wrote:

> Darin McBride <dmcbride@cpan.org> writes:
>
> > Disagreed.  The shell's case statement ...
>
> The shell (what 'the' shell??) only works with strings, creating a whole
> different (and much simpler) playground for comparison and matching.
>

  Whereas Perl (at least Perl 5) usually forces a context.

  I keep thinking that's what Perl ought to do here.  Rather than have a
single C<when> do three different things depending on the "type" of the
match value, have three different, context-forcing case introducers.  At
which point we could relatively easily bundle several.  Modulo nomenclature:

numwhen ($current) { ... }
numwhen (0) { ... }
numwhen (1, -1) { ... }
default { ... }

  I guess we can even handle changing arrays, if we want to:

strwhen (@pre_defined) { ... }
strwhen (@defined) { ... }
strwhen (@seen) { ... }
default ( ... }

  They rather need to be parsed as three different structures in either
case (or overload::Constant will bite us), so why not make them three
different keywords?


Eirik

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