accessing properties from namespace object

Will Coleda will at coleda.com
Mon Jul 4 00:29:23 UTC 2011


On Sun, Jul 3, 2011 at 6:16 AM, rohit jangid <rohit.nsit08 at gmail.com> wrote:
> hi,
>
> I am trying to access the namespace's properties using object notation
>
> .namespace []
> .sub main
> $P0 = box "hello"
> set_global ["rj"], "bill", $P0
> $P1 = get_global ["rj"], "bill"
> say $P1
> $P2 = get_namespace ["rj"]
> say $P2
> $P3 = get_global $P2, "bill"            # using $P2 for accessing
> "bill" property.
> say $P3
> .end
>
> output
>
> [droid at localhost ~]$ parrot new.pir
> hello
> rj
> Null PMC in say
> current instr.: 'main' pc 22 (new.pir:1)
>
> ___________________________________________________________
>
> according to me if I have access to namespace object, I can get all
> the properties stored in it.
>
> while the above is giving Null PMC
> it's alternative
> $P3 = get_global ["rj"], "bill" is working perfectly
>
> am I missing some point ?
>
> thanks...
> --
> Rohit Jangid
> Under Graduate Student,
> Deptt. of Computer Engineering
> NSIT, Delhi University, India
> _______________________________________________
> http://lists.parrot.org/mailman/listinfo/parrot-dev
>

Docs say:

Set $1 to the global named $3 in the namespace denoted by the key constant
$2, relative to the current namespace.  If the namespace or the global
doesn't exist, $1 is set to null.
--

So, you can't expect to use an actual namespace object there; just a
key denoting a namespace.

Now, if you /have/ a namespace, and want to get the sub from in it,
you can do this instead:

$P14 = get_namespace ["rj"]
$P12 = $P14["hello"]
# $P12  = get_global $P14, "hello" # P14 has to be a Key, not a Namespace
$P12()

hope this helps.

-- 
Will "Coke" Coleda


More information about the parrot-dev mailing list