On Mon, Oct 12, 2015 at 03:21:49PM -0400, Eric Brine wrote: > On Mon, Oct 12, 2015 at 1:07 PM, Abigail <abigail@abigail.be> wrote: > > > This is Perl. You can't even trust the source code: > > > > > > use constant; > > use overload::constant integer => sub {"$_[0]"}; > > > > > > when (3) {...} # What does this do? 'eq' or '=='? > > > > If we're basing on the literal as Dave suggested, ==. I don't see a problem > with that. This would be a case of GIGO. If you do something funky, expect > funky things to happen. So, 'use bigint' is something funky? Don't get me wrong, I'd like to have a 'when', and Dave's proposal, while limited to a small subset of what smartmatch once was, is very appealing. It would do almost anything I'd want from a when. But if it turns out that we're still left with something which requires you to know what Perl does at compile time, and it won't play nice with modules that do constant overloading, you'll end up with a feature that's only useable for the handful of people on this mailinglist, and lots of frustrations for the 99.99% of the Perl programmers who don't have this knowledge. And I don't think we should have such a feature. 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). 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" AbigailThread Previous | Thread Next