develooper Front page | perl.perl6.language | Postings from July 2005

Re: Referring to package variables in the default namespace in p6

Thread Previous | Thread Next
From:
=?ISO-8859-1?Q?=22TSa_=28Thomas_Sandla=DF=29=22?=
Date:
July 21, 2005 08:20
Subject:
Re: Referring to package variables in the default namespace in p6
Message ID:
42DFBD24.2050806@orthogon.com
HaloO Matthew,

you wrote:
> I wasn't getting hung up on whether $::($varname) should somehow be 
> cached to avoid a dynamic lookup based on the current value of $varname 
> every time.  And I assume that if $*Main::foo hadn't been created, 
> assigning to $::($varname) would create it as expected (again, without 
> any caching of $varname).

Here your expectations might be disappointed, sorry.

The non-symbolic form $*Main::foo = 'bar' creates code that
makes sure that the lhs results in a proper scalar container.
The symbolic form might not be so nice and return undef!
Then undef = 'bar' of course let's your program die.

Unfortunately I'm unsure how the runtime interface to
making dynamic namespace entries looks like. Note that
the operator ::= acts at compile time, too.

My guess is that the compiler collects all potential data
items and arranges for auto-vivification and/or autoloading
and even on-the-fly instance composition and such like things.
But for symbolics this is your task.


> My confusion initially stemmed from chat on #perl6 about $::Foo and 
> $::('Foo') being Very Different Things - and the fact that there was 
> ever any confusion over whether $::foo was your 'closest' $foo variable 
> or something else.

So to conclude, for reading they amount to the same result but through
different paths. But since the symbolic lookup might result in undef
the behaviour for writing is indeed a Very Different Thing.


@Larry, please correct if I gave wrong advice.
-- 
TSa (Thomas SandlaƟ)



Thread Previous | Thread Next


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