Mark J. Reed wrote:
> Okay, but now we're getting into the fundamental O-O model for
> Perl. I guess that's fair game? You can certainly make the case
> that prototype-based inheritance makes at least as much sense
> as class-based inheritance for a dynamic language like Perl.
> But that's a major implementation change and you have to be careful
> to be sure that "Perl stays Perl".
> [...]
> You could go the Python/JavaScript route and have methods just
> be members that happen to contain code references, so
> $obj.meth(@args) would be a synonym for $obj.{meth}.(@args)
> (or $obj{meth}(@args) with the optional '.'s elided). But then
> you're merging two namespaces that used to be distinct; e.g.
> how do you provide an accessor function with the same name as
> the scalar attribute it's protecting?
>
> While I'm also fond of prototype-based inheritance, I think changing
> the inhertiance model in Perl would be among the most radical
> changes discussed so far. Not to say it's not doable, but I'm
> wondering if it would be worth it or if it would really maintain the
> language's fundamentally Perlish nature.
Good, this thread's found a much more productive path.
For the distinction between methods vs members, I don't think
we have to stray too far from perl-is-perl. Afterall, we already
know that &foo is a function and $foo is a scalar. So from an
implementation perspective there's no problem giving methods
and members a separate namespace. Its just a syntax issue ;-).
We already have a "sub" keyword; and one of its parameters is
the name of the function. Allow that paramter to be a hard
reference to an object, and you've got a way of defining
object-level functions (members are objects):
sub $foo.{bar} { ... } #? === sub $foo.bar { ... } ?
To read the function associated, you can use a property "sub":
$foo.{bar}.sub # returns the subroutine.
calling a property can pass a value, and parentheses are optional:
$foo.{bar}.sub { ... } # context says {} is subroutine composer
So the correspondance, "foo $bar" === "$bar.foo", is maintained.
Now I just need to work out the meaning of "sub $foo {}".
Dave.