develooper Front page | perl.perl5.porters | Postings from December 2019

Re: Aliasing and Read-only variables

Zefram via perl5-porters
December 2, 2019 16:19
Re: Aliasing and Read-only variables
Message ID:
Dave Mitchell wrote:
>    copy   ro  # no P6 equivalent, and not very useful?

Slightly useful: unlike a ro alias, its value couldn't change in a way
that the sub doesn't know about.

>Placeholder direct alias parameters are forbidden. There's no (*$, *@).

I don't see a good reason to forbid these.

>Now for the bikeshedding about what syntax to use for direct aliasing.
>Zefram tentatively proposed using $x\, whereas I propose *$x.

I'm fairly happy with the prefix "*".  I do find it clearer than the
postfix "\".  However, I don't find any of your specific arguments for
it meritorious.  In particular:

>* By having a single syntactical slot to indicate aliasing, that slot can
>  populated with only one of two chars to indicate which type of aliasing
>  is wanted (\$x and *$x). With two slots there's ambiguity: what does
>  \$x\ mean?

"\$x\" would of course be prohibited, just as "*\$x" or "\*$x" would
be prohibited.  I don't find either syntax for both kinds of aliasing at
once to be more or less inviting than the other.  With "\*$x" actually
being legal (and useful) expression syntax, it really doesn't look as
though "\" or "*" syntactically precludes the other.

>* It has a loose mnemonic association with aliasing via typeglob
>  assignment: *foo = ....;.

I find this association to be an argument *against* prefix "*".  The
usage you're proposing has nothing at all to do with typeglobs, so the
association with the glob sigil is misleading.  It also might interfere
a bit with any future work to process actual typeglobs in signatures.
(It's quite feasible to add a facility for lexical glob names in the
future, and there's motivation in that I/O handles are very often wrapped
in globs.)

>* It has a loose association with Perl 6's array flattening syntax, *@a,

This association, too, is misleading, because the facility is semantically
very different.

>There is the question of default behaviour. In Perl 5 currently the
>default is to copy, while in Perl 6 the default is a read-only alias.

The default should remain copying.  Read-only aliasing is nicer
behaviour, but a Perl 5 :ro alias (as you described it) is not, because
of the inability to then pass the variable as a subroutine argument.
Writable aliasing would also be surprising behaviour, because it is
customary to copy arguments, and therefore writing to argument-derived
variables normally doesn't write to the arguments.

>possibility is to make aliasing the default in the presence of :ro.

Too confusing.  Until now, ":ro" has been an attribute that gets
orthogonally composed with other signature features.  Don't break the

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