Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Namespace-sub invocation syntax?

12 views
Skip to first unread message

Luke Palmer

unread,
Nov 23, 2004, 7:22:06 PM11/23/04
to Internals List
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

?

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

Klaas-Jan Stol

unread,
Nov 24, 2004, 5:54:15 AM11/24/04
to Luke Palmer, Internals List
Luke Palmer wrote:

>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

Leopold Toetsch

unread,
Nov 24, 2004, 5:48:10 AM11/24/04
to Luke Palmer, perl6-i...@perl.org
Luke Palmer <lu...@luqui.org> wrote:

> 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

Dan Sugalski

unread,
Nov 30, 2004, 9:33:07 AM11/30/04
to l...@toetsch.at, Luke Palmer, perl6-i...@perl.org
At 11:48 AM +0100 11/24/04, Leopold Toetsch wrote:
>Luke Palmer <lu...@luqui.org> wrote:
>
>> Should there be one for invoking a sub out of a namespace, say:
>
>> .namespace [ "Baz" ]
>
>> .sub quux
>> [ "Foo", "bar" ]()
>
>Looks a bit strange.

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

0 new messages