Hi all,

I've spent some of the afternoon wading through A12 and S10 trying to thoroughly understand scope in perl 6, in light of the death of use vars and the addition of class (as well as package & module) namespaces.

In the process I came up against some confusion concerning how the default package namespace should work. Currently, pugs does:

% pugs -e '$main::foo="foo"; say $foo'
foo

which contradicts S10, which states:

The "::*" namespace is not "main". The default namespace for the main program is "::*Main".

This turned out to be an oversight - but there was then confusion as to how one actually refers to variables in the "::*Main" namespace, as if $Foo::bar looks up the ::Foo object and fetches $bar from it, then presumably $*Main::foo should look up the ::*Main object, and fetch $foo from it.

However (from #perl6):

<autrijus> Arathorn: when you see $Foo::bar, it means looking up the ::Foo object, then fetch $bar from it <autrijus> and ::Foo, just like %Foo, can be lexical or package scoped or global (%*Foo) <autrijus> to restrict the lookup to ::*Foo you can't use the ordinary qualifying syntax, I think.
<autrijus> but I may be completely wrong
<Arathorn> so it sounds as if to get the variable $bar from the global packagename ::*Foo (or just *Foo if disambiguation is not necessary), you'd use $*Foo::bar then.
<autrijus> that may be the case, yes.
<autrijus> $?Foo::bar means $?bar in Foo::
<autrijus> but $*Foo::bar can't mean $*bar in Foo::
<autrijus> because Foo:: will never contain a $*bar.
<autrijus> so it must mean $bar in *Foo::
<autrijus> this is very weird.

So the question is: what is the correct syntax for referring to package variables in the default namespace?

Also, what is the correct syntax for referring to package variables in your 'current' namespace? $::foo? $?PACKAGENAME::foo? $::($?PACKAGENAME)::foo? %PACKAGENAME::<foo>?

cheers,

Matthew.


--
________________________________________________________________
Matthew Hodgson   [EMAIL PROTECTED]   Tel: +44 7968 722968
             Arathorn: Co-Sysadmin, TheOneRing.net®

Reply via email to