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

clarify: how WALK arguments can be combined

6 views
Skip to first unread message

Mark Stosberg

unread,
Sep 4, 2006, 11:32:55 AM9/4/06
to perl6-l...@perl.org

In the Objects chapter, a WALK pseudo-class is spec'ed for using
when calling sets of methods:

http://feather.perl6.nl/syn/S12.html#Calling_sets_of_methods

These are the arguments listed that can be used with WALK:

:canonical # canonical dispatch order
:ascendant # most-derived first, like destruction order
:descendant # least-derived first, like construction order
:preorder # like Perl 5 dispatch
:breadth # like multi dispatch


First, it would be nice if the comments "like Perl 5" and "like multi
dispatch" could be expanded, if only to provide references to their
complete specs. Also, if "canonical" means something besides "I don't
care", it would be nice to have a reference for that, too.

My concern for the moment is clarification how these options can be
combined. Clearly, combining ":ascendant" and ":descendant" doesn't make
sense.

But, I assume a "self.*meth" call can work along both the inheritance
axis and the multi method access.

Therefore, it seems fair to combine one option that affects each axis.

As a "use case", in CGI::Application we traverse classes ":ascendant"
but then execute what would be "multi methods" in the order they are
defined, which sounds like perhaps ":preorder" to me.

Mark

Brad Bowman

unread,
Sep 4, 2006, 10:41:14 PM9/4/06
to Mark Stosberg, perl6-l...@perl.org
Mark Stosberg wrote:
> In the Objects chapter, a WALK pseudo-class is spec'ed for using
> when calling sets of methods:
>
> http://feather.perl6.nl/syn/S12.html#Calling_sets_of_methods
>
> These are the arguments listed that can be used with WALK:
>
> :canonical # canonical dispatch order
> :ascendant # most-derived first, like destruction order
> :descendant # least-derived first, like construction order
> :preorder # like Perl 5 dispatch
> :breadth # like multi dispatch
>
> First, it would be nice if the comments "like Perl 5" and "like multi
> dispatch" could be expanded, if only to provide references to their
> complete specs. Also, if "canonical" means something besides "I don't
> care", it would be nice to have a reference for that, too.

I think Class::C3 on CPAN describes and implements the Perl 6 dispatch
algorithm in Perl 5. I don't know if it's in the Synopses, etc.

> My concern for the moment is clarification how these options can be
> combined. Clearly, combining ":ascendant" and ":descendant" doesn't make
> sense.
>
> But, I assume a "self.*meth" call can work along both the inheritance
> axis and the multi method access.
>
> Therefore, it seems fair to combine one option that affects each axis.

Wouldn't ":breadth" just be the breadth first order of the same set
of methods? Mentioning multi dispatch kind of confusing...

So I think the permitted combinations are:

One sorting adverb (defaulting to :canonical):
:canonical, :ascendant, :descendant, :preorder, :breadth

Some number of filtering adverbs:
:super # only immediate parent classes
:method<name> # only classes containing method declaration
:omit(Selector) # only classes that don't match selector
:include(Selector) # only classes that match selector

There does seems to be a bit of slack in this section of the Synopsis,
particularly with regard to multi methods. Perhaps I'm just reading
out of context.

> As a "use case", in CGI::Application we traverse classes ":ascendant"
> but then execute what would be "multi methods" in the order they are
> defined, which sounds like perhaps ":preorder" to me.

I'd like to be able to access the list of methods returned by
the WALK traversal. Perhaps it is:

@methods = $object.*WALK::can('meth');

You may want to combine method calls in other ways, with
a short circuiting && or || for example. "last METHOD" could be
used to short-circuit but then the methods can't be composed
using with different logic.

Maybe some of the adverbs above could be replace by a grep on the
method list. Although, a) short-hand++ b) the grep is dynamic
and the adverbs are declarative.

Brad

--
There are two things that will blemish a retainer, these are riches and
honor. But if one remains in strained circumstances he will not be
marred. -- Hagakure http://bereft.net/hagakure/

Mark Stosberg

unread,
Sep 5, 2006, 12:41:04 PM9/5/06
to perl6-l...@perl.org
Brad Bowman wrote:
> Mark Stosberg wrote:
>> In the Objects chapter, a WALK pseudo-class is spec'ed for using
>> when calling sets of methods:
>>
>> http://feather.perl6.nl/syn/S12.html#Calling_sets_of_methods
>>
>> These are the arguments listed that can be used with WALK:
>>
>> :canonical # canonical dispatch order
>> :ascendant # most-derived first, like destruction order
>> :descendant # least-derived first, like construction order
>> :preorder # like Perl 5 dispatch
>> :breadth # like multi dispatch
>>
>> First, it would be nice if the comments "like Perl 5" and "like multi
>> dispatch" could be expanded, if only to provide references to their
>> complete specs. Also, if "canonical" means something besides "I don't
>> care", it would be nice to have a reference for that, too.
>
> I think Class::C3 on CPAN describes and implements the Perl 6 dispatch
> algorithm in Perl 5. I don't know if it's in the Synopses, etc.

So that would the "preorder" or the "canonical" case. In either case,
since multi methods don't (normally) exist in Perl 5, it's still not
clear what order multi methods will be resolved in.

>> My concern for the moment is clarification how these options can be
>> combined. Clearly, combining ":ascendant" and ":descendant" doesn't make
>> sense.
>>
>> But, I assume a "self.*meth" call can work along both the inheritance
>> axis and the multi method access.
>>
>> Therefore, it seems fair to combine one option that affects each axis.
>
> Wouldn't ":breadth" just be the breadth first order of the same set
> of methods? Mentioning multi dispatch kind of confusing...
>
> So I think the permitted combinations are:
>
> One sorting adverb (defaulting to :canonical):
> :canonical, :ascendant, :descendant, :preorder, :breadth
>
> Some number of filtering adverbs:
> :super # only immediate parent classes
> :method<name> # only classes containing method declaration
> :omit(Selector) # only classes that don't match selector
> :include(Selector) # only classes that match selector

I agree in general, but still wonder about how the details sorting
adverbs apply to multi methods AND inherited methods.

> I'd like to be able to access the list of methods returned by
> the WALK traversal. Perhaps it is:
>
> @methods = $object.*WALK::can('meth');

That looks potentially useful. The "use case" might be checking to see
which which methods /might/ be called and then perhaps changing or
avoiding the method set call based on the result.

Mark

0 new messages