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

Re: Revisiting smart match

Thread Previous | Thread Next
Father Chrysostomos
November 27, 2017 18:59
Re: Revisiting smart match
Message ID:
> Finally, having specific syntax for both forms of "when" raises the
> question of what postfix "when" should do.  It doesn't have mandatory
> bracketing of the condition operand, so we can't just make a parallel
> change to its syntax.  We could have postfix "when" always do smartmatch,
> or always take a truth value, or become different from all other
> postfix modifiers by requiring bracketing of the condition expression,
> or be abolished.  I have no real preference between these, except that
> if we're Huffman coding the prefix "when" forms then a fixed choice of
> semantic for postfix "when" should probably match whatever got the shorter
> "when()" syntax.

The bracketing of the expression after 'when' and 'if' is only neces-
sary because of the ambiguity that arises when a brace follows it.
There is no opening brace following a postfix expression, so

    foo when ?bar;

would be unambiguous.  I am not saying I particularly like the syntax,
just that it is possible.

Do bear in mind, though, that 'when' with a simple truth value can be

    if (cond) { ...; break }

which is not actually that long.  The real problem arises if people
forget the 'break', but elsif comes to the rescue.  Hmm, this is
starting to sound like the old 'Perl doesn't need a switch' meme,
which I do not entirely disagree with:

    given (thingy) {
        if (groovy($_)) {
        elsif (runcible($_)) {

which actually reads quite well.  But you cannot easily combine that
with 'when' without the forgot-the-break problem.

Just brainstorming....

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