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

Re: Revisiting smart match

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
August 2, 2017 18:43
Subject:
Re: Revisiting smart match
Message ID:
20170802184255.2949.qmail@lists-nntp.develooper.com
Zefram wrote:
> Father Chrysostomos wrote:
> >This came up before.  The previous proposal was to keep smartmatch for
> >when(){}, and to disable it for when{}{} (with a true block for the
> >protasis).
> 
> To "keep" what, exactly?

I should have written 'use', not 'keep'.

> What we have now for when() is not consistent
> use of smartmatch, it's inconsistent.  I'm not wedded to the particular
> assignment of bracket types to semantics (though I like the consistency
> of my suggestion with if()), but I do think that each semantic on offer
> ought to be consistent in how it treats any expression.  We should not
> keep the existing rule, under any syntax.

Agreed.

Concerning 'continue' and 'break', I miswrote in my previous message
that I suggested that 'continue' be a synonym for 'next' and 'break'
be a synonym for 'last'.  Obviously that is insane, as perhaps am I.
(That is *not* what I earlier suggested.)

'break' should be a synonym for 'next', not 'last'.  And 'continue'
only applies inside a 'when' block, which is fine.

> But amusingly "break" and "continue" don't generate experiment warnings,
> and (like last et al) they're resolved dynamically.  So "use feature
> 'switch'; sub foo { break; }" compiles and ostensibly does not invoke
> experimental behaviour.  (Unlike last et al, there isn't even a warning
> for exiting a subroutine that way.)  To make significant use of that sub
> some other code would have to use "given" or "when", which does yield an
> experiment warning.  But code that just invokes "break" without using
> "given" or "when" gets no experiment warning and gets behaviour that's
> quite different from your proposal of it being synonymous with "last".

But the only case in which one can use 'break' without getting an
error message is inside 'given', which is experimental.  I.e., you get
an experimental warning or an error message whenever you actually exe-
cute the break op.

Anyway, this is madness:

$ perl5.24.0 -E 'given($_) { for($_){break} }'
given is experimental at -e line 1.
Can't "break" in a loop topicalizer at -e line 1.

$ perl5.24.0 -E 'given($_) { while(1){break} } print "ok\n"'
given is experimental at -e line 1.
ok

> That might limit your options in redefining these keywords.

I think not.  (If Descartes is right, maybe that means I am not.)

Also, remember that given and when did not always emit experi-
mental warnings.

Another idea: Deprecate 'break' and make 'when' do an implicit 'last'
(which it already does inside a for-loop).

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