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

Re: square signatures

Thread Previous
From:
Zefram
Date:
November 13, 2017 21:45
Subject:
Re: square signatures
Message ID:
20171113214545.GW4913@fysh.org
Father Chrysostomos wrote:
>Since anonymous arrays are very common, and file globbing is rela-
>tively rare, perhaps this would be a better syntax:
>
>    sub mul ($$) <$x, $y> { $x * $y }

That interacts poorly with default value expressions.  "($a = $b > $c)"
is a legal signature (under the current syntax); with angle brackets
">" in that place would be ambiguous between comparison operator and
signature delimiter.  The next character after the comparison operator
could even be "{" for maximum confusion.  We have no precedent for angle
bracketing of arbitrary expressions.  The delimiter really has to be
something that we use specifically to enclose expressions, and there
aren't many options available there.

>Also, you never see file globbing that looks like <$a, $b>, so it is
>hard to confuse them.

You do get stream reads of the forms "<$a>" and "<>", which would be
very common signatures.

If simple square brackets look too much like array construction, we
could go to composite delimiters:

    sub mul ($$) <[$x, $y]> { $x * $y }

but that seems unPerlishly cumbersome.

>I will just add that I fully support putting attributes before signa-
>tures, the way they used to be in 5.20.

Thanks, but that doesn't belong on this thread.  The placement of
signatures relative to attributes is almost entirely orthogonal to
the choice of delimiter.  (There's a little bit of interaction in that
changing the delimiter would get rid of the whitespace sensitivity that
occurs with ":bar($a)" (attribute with argument) versus ":bar ($a)"
(attribute followed by signature) when the signature follows attributes.)
Your comment would be better on [perl #132141], where none of the
supporters of signatures preceding attributes have yet suggested how to
resolve the bug that that change introduced.

-zefram

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About