Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > d92aa75c2d384ff9f513aed09a46f703 > files > 853

parrot-doc-3.1.0-2.mga1.i586.rpm

# Copyright (C) 2007-2009, Parrot Foundation.

=head1 Subroutines in a Namespace

Subroutines created in one namespace can be accessed from another
using the C<get_global> opcode, just like global variables. In fact,
since subroutines are really just PMCs, they are variables themselves
and the two operations are actually the same.

Namespaces can be defined in code using the C<.namespace> directive,
followed by the name of the namespace as a hash key. The default root
namespace can be specified with an empty set of brackets such as
C<.namespace []>.


=cut

.sub main :main

   $P0 = get_global ["Different"; "Namespace"], "foo"

   $S0 = $P0("Zaphod")
   say $S0

.end

.namespace ["Different"; "Namespace"]

.sub foo
    .param string name

    .local string greeting
    greeting = "Hello, " . name

    .return (greeting)
.end

# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: