On 8/5/05, Ingo Blechschmidt <[EMAIL PROTECTED]> wrote:
> Hi,
>
> my $str = "Hello";
> $str.ref = Int; # allowed?
> $str.meta = &some_sub.meta; # allowed?
I hardly think those work. Both of those require a change of
implementation, which we can't do generically. So people would have
to specify how the implementation changes in that way, which they
generally won't/can't. You can do the first using user-defined
methods like so:
$str = $str as Int # $str as= Int ?
I'm not sure about the latter.
> my $str = "Hello";
> Str ::= Int; # allowed?
> ::Str ::= ::Int; # or is this allowed?
One of these two is probably allowed. But maybe it should be louder.
> say $str; # still "Hello"? Or is it an Int now?
That's a hard question. If say is implemented like so (this is
hypothetical; it will surely be implemented in terms of print):
multi say () { internal_put_str "\n" }
multi say (*$first, [EMAIL PROTECTED]) {
given $first {
when Str { internal_put_str $first }
when Int { internal_put_int $first }
...
}
say @stuff;
}
Then the first case becomes equivalent to "when Int", which would call
internal_put_str with an Int, which could be very dangerous. This is
why rebinding names globally is a bad idea. And in that case, I don't
know how or whether we should provide the ability.
Globally subclassing, however, isn't so dangerous:
Str does role {
method blah () {...}
};
But then comes to your question:
my $foo = "hello";
Str does role {
method blah () {...}
};
$foo.blah; # allowed
That is, do existing Strs all "does" the new role as well?
Luke