.sub foo
# ...
.end
.sub bar
foo()
.end
Should there be one for invoking a sub out of a namespace, say:
.namespace [ "Foo" ]
.sub bar
# ...
.end
.namespace [ "Baz" ]
.sub quux
[ "Foo", "bar" ]()
.end
?
On a related note, are we supposed to name our namespaces [ "Foo", "Bar" ]
or [ "Foo::Bar" ] nowadays? If the former, how do we name our classes?
Do we have to mangle those ourselves, or is there a way to put a class
in a namespace?
Luke
>Since there is a syntax for invoking subs:
>
> .sub foo
> # ...
> .end
>
> .sub bar
> foo()
> .end
>
>Should there be one for invoking a sub out of a namespace, say:
>
> .namespace [ "Foo" ]
>
> .sub bar
> # ...
> .end
>
> .namespace [ "Baz" ]
>
> .sub quux
> [ "Foo", "bar" ]()
> .end
>
>?
>
>
I would suggest a slightly adapted form:
.sub quux
[ "Foo" ] bar()
.end
if quux is in the same namespace (i.e. Foo), then this namespace
specifier is not necessary, so that's a bit more clean when one does:
.sub quux
[ "Foo" ] bar()
bar()
.end
I know it's not important at the moment, but this is what I would prefer.
klaas-jan
> Should there be one for invoking a sub out of a namespace, say:
> .namespace [ "Baz" ]
> .sub quux
> [ "Foo", "bar" ]()
Looks a bit strange.
Class methods already have their namespaces. For subs we could do:
.locale pmc ns, ns_foo
ns = interpinfo .CURRENT_NAMESPACE # or .TOPLEVEL_NAMESPACE
ns_foo = ns ["Foo"]
ns_foo."bar"()
The namespace PMC provides the find_method() that's actually behind that
call. With the additional benefit that it's using the method cache too.
> On a related note, are we supposed to name our namespaces [ "Foo", "Bar" ]
> or [ "Foo::Bar" ] nowadays?
Nested namspaces BTW: [ "Foo"; "Bar" ] aren't yet supported. Missing is
also the namespace name mangling (appending a NUL). The colon separated
thing is just one namespace - no nesting at all.
> ... If the former, how do we name our classes?
> Do we have to mangle those ourselves, or is there a way to put a class
> in a namespace?
I think to create a nested class, we need something like:
set_namespace ["Foo"]
subclass cl, "Foo", "Bar"
...
.namespace ["Foo" ; "Bar" ]
methods
> Luke
leo
I think for this being explicit is fine:
$P1 = global ["Foo"], "bar"
$P1()
>Class methods already have their namespaces. For subs we could do:
>
> .locale pmc ns, ns_foo
> ns = interpinfo .CURRENT_NAMESPACE # or .TOPLEVEL_NAMESPACE
> ns_foo = ns ["Foo"]
>
> ns_foo."bar"()
>
>The namespace PMC provides the find_method() that's actually behind that
>call. With the additional benefit that it's using the method cache too.
Hrm. No, I don't think this is the right way to go for this, and I
don't think it ought to use the method cache. It'll certainly screw
up code that does the sensible thing and looks to see if an object
was passed to see if it was invoked as a method or sub.
Subs aren't methods, and shouldn't be invoked as such. They really
*are* subs, and at best the invocation should be:
ns_foo["bar"]()
except we don't do that any more.
This should be a two step thing, doing a fetch and then sub invoke.
> > ... If the former, how do we name our classes?
>> Do we have to mangle those ourselves, or is there a way to put a class
> > in a namespace?
This is turning out to be a more complex issue. Namespaces might not
be the right answer here.
--
Dan
--------------------------------------it's like this-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk