David Green wrote:
> Or to look at it the other way around:  Since we refer to things by name,
> those names have to be unique everywhere; so let's start out with long,
> "fully-qualified" names everywhere: $dog.Dog::bark(), $tree.Tree::bark(),
> $i.Int::succ, etc.  Now everything's fine -- except that our fingers are
> getting tired from all that typing.  We want to use shortcuts to say things
> like $dog.bark, because there's only one place that $dog can legitimately
> find a bark() method, and that's in the Dog class, so both we and Perl can
> easily figure out what is meant.
>
> On the other hand, $dogwood.Dog::bark cannot be simplified by leaving out
> the "Dog::" because then it would be ambiguous.  But if we look at it as
> starting with full names everywhere, and seeing what we can leave out
> (rather that starting with short names and having to add stuff in), I think
> it's not surprising.

On the gripping hand, if we have a function "train(Dog $d)", then we
can safely assume that within the lexical scope of train, $d is
supposed to be treated as a Dog.  So within that lexical scope, it
should be safe to leave off the "Dog::".  If you pass $dogwood into
this method, the ambiguity between Dog::bark and Tree::bark gets
resolved in favor of the former; so $d.bark _still_ barks like a Dog,
even though $d is actually a Dogwood.  That's what I was meaning when
I talked about wearing hats: while it's within the train() sub,
$dogwood is wearing its Dog hat and barks like a Dog.

>> I really don't think that deferring the decision works.  The "freezing"
>> technique described in the paper allows the consumer, C, to statically bind
>> the method foo() in the methods in the appropriate role which call it.
>
> The problem with "freezing" some methods into private ones is that those
> methods weren't meant to be private; if my role provides a .bark method, I
> need to be able to call it.

And more to the point, subs that aren't expecting a Dogwood should
still be able to accept it in its role as a Dog, call .bark, and
expect it to bark like a Dog.

-- 
Jonathan "Dataweaver" Lang

Reply via email to