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

Re: Symbolic dereferentiation of magical variables

Thread Previous | Thread Next
From:
Ingo Blechschmidt
Date:
August 22, 2005 13:59
Subject:
Re: Symbolic dereferentiation of magical variables
Message ID:
deddt9$ka6$1@sea.gmane.org
Hi,

Larry Wall wrote:
> On Sat, Aug 20, 2005 at 10:33:03PM +0000, Ingo Blechschmidt wrote:
> : S02 says:
> :     our $a; say $::("a");     # works
> :  
> :     my $a; say $::("a");      # dies, you should use:
> :     my $a; say $::("MY::a");  # works
> 
> That looks like somebody's relic of Perl 5 thinking.  Personally,
> I don't see why the second one should die.  I was kind of hoping
> that symbolic lookups would include lexicals in Perl 6, unlike in
> Perl 5.  Then you use MY or OUR to force it one way or the other.

I like that very much! :)

> : How can I use symbolic dereferentiation to get $?SELF, $?CLASS,
> : ::?CLASS, %MY::, etc.?
> :  
> :     say $::('$?SELF');        # does this work?
> 
> Probably not, since the ::() notation doesn't want sigils in the key,
> and you have to say
> 
>     $?::('SELF')
> 
> to have any hope of it working.  On the other hand
> 
>     %MY::<$?SELF>
> 
> might get you the symbol out of the symbol table hash,

ok.

> unless $?SELF is too macro-y for that.  $? variables aren't required
> to have a dynamically lookupable meaning at run time, since their
> native dynamic context is the compiler, not the run-time.

Makes perfect sense.

> 
> :     say $::('MY::$?SELF');    # or this?
> 
> No, we don't currently allow sigils after ::.

I took that straight from S02 :):
> All symbolic references are done with this notation:
> 
>     $foo = "Foo";
>     $foobar = "Foo::Bar";
>     $::($foo)           # package-scoped $Foo
>     $::("MY::$foo")     # lexically-scoped $Foo
>     $::("*::$foo")      # global $Foo
>     $::($foobar)        # $Foo::Bar
>     $::($foobar)::baz   # $Foo::Bar::baz
>     $::($foo)::Bar::baz # $Foo::Bar::baz
>     $::($foobar)baz     # ILLEGAL at compile time (no operator baz)

> and such.)  I think I like the option lowering the sigil to the key.
> Maybe the outer sigil is meaningless in that case, and it's just
> 
>     OUTER::OUTER::<$_>
> 
> But if we say that any package/type name can tagmemically function
> as a hash if you use like one, then the last :: can go too:
> 
>     OUTER::OUTER<$_>
>     OUTER::OUTER{'$_'}

I like those, especially as we've said that the sigils are part of the
variable name.

> Though we're getting close to confusing this notation with
> 
>     %OUTER::OUTER::{'$_'}
> 
> which looks similar, but (if we take the Perl 5 meaning) doesn't
> do :: splitting on the key.  In other words, this would also get
> to OUTER::OUTER<$_>:
> 
>     OUTER{'$OUTER::_'}
> 
> because it's accessing through the package as a hash and does further
> :: breakdown.  But this wouldn't work:
> 
>     %OUTER::{'$OUTER::_'}
> 
> because it's accessing through the actual symbol table hash, which
> doesn't have any such symbol as one of its keys.
> 
> That's an awfully subtle distinction, though.  I think OUTER::OUTER's
> symbol table hash needs a better name than %OUTER::OUTER.  Maybe it's
> named OUTER::OUTER<%OUR> or OUTER::OUTER::<%MY> or some such.

Makes sense.

> Which makes me think that Perl 5's %FOO::{'name'} symbol table
> notation is really bogus, because %OUTER:: doesn't really refer to a
> single symbol table in Perl 6, but the starting place for a symbol
> search that may span several symbol tables.

If we go with these changes, this functionality  (starting place for a
search) would be available by using

    Foo::Bar<$symbol_to_lookup>;  # right?


--Ingo

-- 
Linux, the choice of a GNU | self-reference, n. - See self-reference  
generation on a dual AMD   | 
Athlon!                    | 


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