Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Symbolic references and twigils

1 view
Skip to first unread message

Joshua Choi

unread,
Jan 21, 2006, 12:37:40 PM1/21/06
to perl6-l...@perl.org
Supposed I wanted to refer to $.head using a symbolic reference--how
would I do it?

my $varname = 'head';
#1 say $.::($varname);
#2 say $::('.' ~ $varname);
#3 something else


Larry Wall

unread,
Jan 21, 2006, 3:35:32 PM1/21/06
to perl6-l...@perl.org
On Sat, Jan 21, 2006 at 10:37:40AM -0700, Joshua Choi wrote:
: Supposed I wanted to refer to $.head using a symbolic reference--how

I'd say #1 is easiest to grok, insofar as it identifies at compile time
which namespace you're searching at run time. #2 is rather strange,
but conceivably gives you greater flexibility, at the expense of making
certain leading characters illegal in whatever the default search
space is. That's probably bad. If we pattern it after MY::<$foo>
and OUR::<$foo> and GLOBAL::<$foo> and COMPILING::<$foo>, then #3
might look like this:

SELF::{$varname}

where $varname probably includes the sigil but maybe not the twigil.

Though in this particular case, since $.foo is always virtual anyway,
you could always just say

self.$varname

to mean the same thing. Presumably you can even get at private
variables using indirect private method syntax:

self!$varname

Larry

0 new messages