On 4/16/07, Allison Randal <[EMAIL PROTECTED]> wrote:
Here's the original post where I gave the rationale for making the flags
work as they do:
<http://groups.google.com/group/perl.perl6.internals/browse_thread/thread/5bbf1eab0133d467?tvc=2>
From the link: <<END
This is the main thing Chip and I talked about in our last face-to-face
meeting. We came up with 3 basic parameters: whether a method is a
vtable method, whether it has a vtable name distinct from the method
name, and whether it has a method name at all (or is anonymous, i.e.
only a vtable method). The interface I scrawled out over coffee is:
# method name is the same as vtable name
.sub get_string :method :vtable
# accessible as either $obj.stringify() or vtable
.sub stringify :method :vtable('get_string')
# accessible only as vtable
.sub get_string :method :anon :vtable
.sub stringify :method :anon :vtable('get_string')
Which reuses the existing concept of:
# method has an entry in the namespace
.sub stringify :method
# method has no entry in the namespace
.sub stringify :method :anon
END
This seems perfectly fine to me. The only change I think should be
made is that :vtable automatically sets :method to true. Using :anon
to exclude it from the namespace is what you originally proposed, so
I'm curious why you've changed your mind.
I'm comfortable with a modification saying that :vtable always gets the
'self' parameter like :method does. But without :method, :vtable should
not make an entry in the namespace of the class, or call 'add_method' on
the class. This results in simpler syntax for the cases where you only
want to override the vtable entry.
Making :method mean one thing when used with :vtable, and something
completely different without, seems like a really bad idea to me, and
is confusing to the user. The user will also be confused because
adding :vtable removes it from the namespace, which they didn't
explicitly ask it to do. What is :anon good for if we use a
completely different system for :vtable?
Here are the semantics you've proposed:
.sub get_string # normal sub, attached to a namespace but not a method
.sub get_string :method # a full method, attached to a namespace
.sub get_string :vtable # a vtable method, but not attached to a
namespace (user wonders why, since methods are attached to their
namespace)
.sub get_string :vtable :method # adding :method attaches it to a
namespace (*not* what :method means without :vtable - user wonders why
they need it, since it's already a method)
.sub get_string :vtable :anon # unspecified
.sub get_string :vtable :method :anon # now we're in trouble
The same thing, with what I've proposed:
.sub get_string # normal sub, attached to a namespace but not a method
.sub get_string :method # a full method, attached to a namespace
.sub get_string :vtable # a method that also overrides the vtable
.sub get_string :vtable :method # same as before
.sub get_string :vtable :anon # same, but not attached to the
namespace (note that the user has actually specified this, so they
expect it to happen)
.sub get_string :vtable :method :anon # same as before
--
Alek Storm