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

Re: Revisiting smart match

Thread Previous | Thread Next
November 27, 2017 23:56
Re: Revisiting smart match
Message ID:
Father Chrysostomos wrote:
>If we can make 'break' equivalent to 'next', then I will likely use
>'when' frequently.

Are you referring purely to the "break" keyword here, or also to the
implicit jump at the end of a "when" block?  I'm guessing the latter,
and that you'd mostly not have explicit "break"s, but you're saying
you'd use "when" in types of loop other than "foreach".

Making the implicit jump a "next" seems sensible.  I'm dubious about
having a "break" keyword as a synonym of "next", because it would increase
the confusion that arises when comparing the loop control keywords to C.
C's "break" is (when applied to loops) our "last", so to have a "break"
that behaves like C's "continue" seems like it's asking for trouble.
How would you feel about having no "break" keyword at all, and just using
"next" or "last" to get out of a "given"?

>                                So I definitely support having separ-
>ate keywords, as long as they are sufficiently memorable and not

OK.  I suggest "having" for smartmatch and "being" for condition.
They show some thematic relationship to each other, and "being" is
stylistically quite distinct from "if" (whereas "when" is nearly a
synonym for "if", and brings in misleading temporal connotations).
So the earlier example would be

    given ($input) {
        being ($_ eq "string") { die "A" }
        being ($_ == 90210)    { die "B" }
        having ($matcher)      { die "C" }

"being" should be mentally read as "it being that", and "having" as
"having a".  In the example above, "having($matcher)" doesn't read well,
but "having(Number)" and suchlike would flow nicely.

If we're mucking about with these keywords, we should also consider
respelling "default", which reads poorly and seems to have been copied
too directly from C.  An adverbial phrase is required to introduce a
conditionally-executed block.  I suggest "generally" for the default
action.  For consistency, we should also have "generally" available as
a postfix.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About