
abigail at abigail
Aug 29, 2012, 1:43 AM
Post #12 of 14
(86 views)
Permalink
|
On Tue, Aug 28, 2012 at 06:02:33PM -0500, Jesse Luehrs wrote: > On Tue, Aug 28, 2012 at 06:52:35PM -0400, David Golden wrote: > > On Tue, Aug 28, 2012 at 5:06 PM, Jesse Luehrs <doy [at] tozt> wrote: > > > > > I think people will have fewer reservations about accepting weird > > > special cases like this for a keyword-based control structure > > > (especially considering the precedent set by while (<>), etc) than for > > > an infix operator (since it will be a weird special case either way - > > > "why can i do '$foo ~~ 1', but not '$a = 1; $foo ~~ $a'?". > > > > > > > > The opportunity for confusion exists either way. My suggestion is to > > change *one* thing -- smartmatch -- instead of *two* things -- smartmatch > > and when. > > > > Then all people have to know/relearn is the smartmatch table, not the > > smartmatch table *and* the special case rules for when. > > But this *is* a change to when, that's what I'm saying. From perlsyn: > > Exactly what the EXPR argument to "when" does is hard to describe > precisely, but in general, it tries to guess what you want done. > Sometimes it is interpreted as "$_ ~~ EXPR", and sometimes it does > not. It also behaves differently when lexically enclosed by a > "given" block than it does when dynamically enclosed by a "foreach" > loop. The rules are far too difficult to understand to be described > here. See "Experimental Details on given and when" later on. > > For instance, currently "when ($a && $b)" means > "when ($_ ~~ $a && $_ ~~ $b)". > Yeah, but "when (2 && 3)" does *NOT* mean when ($_ ~~ 2 && $_ ~~ 3) as '2 && 3' gets constant folded: $ perl -MO=Deparse -E 'given ($_) {when (2 && 3) {say}}' use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval'; given ($_) { when (3) { say $_; } } -e syntax OK $ Which, IMO, is a misfeature of a (mis?)feature. Abigail
|