Larry Wall wrote:
Presumably
$obj does (A,B,C)
could also be made to work even with non-associative does.
Right.
Note that you _do_ want to be able to do something to the effect of
ordered composition in a single statement, though:
role A {
...
method m { ... }
}
$x does A;
A.m will override $x.m - assuming that $x.m exists at all. As such,
you end up with an anonymous class with an undefined method - a
distinct no-no.
Maybe what you need to say is that "$x does ..." is a macro that
treats what follows as part of an anonymous class definition. So
$x does A does B { method m { doit } }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
would be equivalent to something like
$x.WHAT := class is $x.WHAT does A does B { method m { doit } }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You'd need to have the macro work some magic involving curly-braces
and terminating semicolons, so that
$x does A;
doit;
...
becomes
$x.WHAT := class is $x.WHAT does A { }
doit;
...
instead of
$x.WHAT := class is $x.WHAT does A {
doit;
...
}
And you'd have to decide what to do with
$x does role { ... }
{ ... }
Should this become
$x.WHAT := class is $x.WHAT does role { ... } { ... }
or
$x.WHAT := class is $x.WHAT does role { ... } { }
{ ... }
?
But otherwise, this approach allows runtime composition to use exactly
the same syntax and semantics as compile-time composition as soon as
you hit infix:<does>.
--
Jonathan "Dataweaver" Lang