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

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

Thread Previous | Thread Next
From:
Ed Avis
Date:
August 17, 2012 03:39
Subject:
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
loom.20120817T122545-447@post.gmane.org
Hmm, I understand the enthusiasm for magic junction types like 'any', since
Perl 6 has them, and Perl 6 is somehow related to Perl 5 in some way, but I
still feel that a simple 'in' operator would be far more straightforward.

    if ($x in @a)

Reading that you immediately see what it is going to do: the Perl interpreter
will loop over each element in @a, do an equality comparison against $x (and
I do entirely agree that string equality is the way to go) and stop when one
is found.

The semantics of 'any' are much less straightforward, especially if you want
to reason about memory usage.  Does creating the junction object involve taking
a copy of the array?  More importantly, the 'any' junction cannot be used to
implement a list membership test that works in all cases.

    my $j1 = any(qw(a b));
    my $j2 = any(qw(c d));
    my $j = any($j1, $j2);
    if ('a' eq any($j)) { say 'yes a' }
    if ($j1 eq any($j)) { say 'yes j1' }

Clearly, it cannot be the case that both 'a' and $j1 are members of the list
($j1, $j2).  Junctions surely have all sorts of interesting uses, but they are
not a substitute for a simple list membership operator.

Let's use the simplest possible syntax, with the simplest possible semantics.

-- 
Ed Avis <eda@waniasset.com>




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