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:
Eirik Berg Hanssen
Date:
October 7, 2015 18:21
Subject:
Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]
Message ID:
CAHAeAG4Vj-n8=zagqsw68JZDc9PxGaB-wkihfe5O1dxton0LMw@mail.gmail.com
On Wed, Oct 7, 2015 at 10:24 AM, Dave Mitchell <davem@iabyn.com> wrote:

> I think 95% of what people actually *want* a smartmatch system for is so
> that they can write code of one of these three forms:
>
>     given ($index) {
>         when (undef)     {...}
>         when (0)         {...}
>         when (1)         {...}
>         when (INDEX_MAX) {...}
>     }
>
>     given ($string) {
>         when (undef) {...}
>         when ("foo") {...}
>         when ("bar") {...}
>         when (BAZ)   {...}
>     }
>
>     given ($string) {
>         when (undef) {...}
>         when (/foo/) {...}
>         when (/bar/) {...}
>     }
>

  If you are doing away with polymorphism, why squeeze these three
different semantics into a single keyword?

  Why not let the programmer write what he means explicitly, rather than
implicitly on compile-time "type"?  I'm sure the maintainer would prefer
(modulo obvious bikeshedding):

    given ($index) {
        when (undef)     {...}
        ncase (0)         {...}
        ncase (1)         {...}
        ncase (INDEX_MAX) {...}
    }

    given ($string) {
        when (undef) {...}
        scase ("foo") {...}
        scase ("bar") {...}
        scase (BAZ)   {...}
    }

    given ($string) {
        when (undef) {...}
        when (/foo/) {...}
        when (/bar/) {...}
    }

  … well, at least this maintainer would …


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