[PDD] Add docs for the Parrot_PMC_push_* and Parrot_PMC_pop_* functions
[parrot.git] / examples / tutorial / 62_namespaces.pir
blob873ec853a8e6b49ec22a81ace76040d91c7ceaf4
1 # Copyright (C) 2007-2009, Parrot Foundation.
2 # $Id$
4 =head1 Subroutines in a Namespace
6 Subroutines created in one namespace can be accessed from another
7 using the C<get_global> opcode, just like global variables. In fact,
8 since subroutines are really just PMCs, they are variables themselves
9 and the two operations are actually the same.
11 Namespaces can be defined in code using the C<.namespace> directive,
12 followed by the name of the namespace as a hash key. The default root
13 namespace can be specified with an empty set of brackets such as
14 C<.namespace []>.
17 =cut
19 .sub main :main
21    $P0 = get_global ["Different"; "Namespace"], "foo"
23    $S0 = $P0("Zaphod")
24    say $S0
26 .end
28 .namespace ["Different"; "Namespace"]
30 .sub foo
31     .param string name
33     .local string greeting
34     greeting = "Hello, " . name
36     .return (greeting)
37 .end
39 # Local Variables:
40 #   mode: pir
41 #   fill-column: 100
42 # End:
43 # vim: expandtab shiftwidth=4 ft=pir: