Dan Sugalski wrote:
> >In a certain way, overloading is a way to attach magic to a value, in
Perl5.
> >I don't know how it's implemented, but if $a contains an object that has
> >overloaded behaviour, and I do $b = $a, $b will contain a pointer to the
> >same object, with the same overloaded behaviour.
>
> It shouldn't. What $b should have is a *copy* of the data in $a, with the
> same overloading magic. Otherwise altering $a would alter $b, which isn't
> what you want.
>

That's why I propose separating add/subtract/multiply/... magic from
store/fetch magic. The former should be passed with the value (because it is
what gives meaning to the value), while the latter is really a thing of tied
variables.



> >I think in Perl5, it's not
> >possible to attach magic behaviour to an individual object, but only to a
> >class of them, so it wouldn't be possible to attach magic to the string
> >"foo", for instance...
>
> Magic can only be attached to individual [SAHG]Vs. It can't be attached to
> whole classes of things.

Sorry, wrong terminology. I was talking about overloading, which is kind of
magic in the sense that it does something special too...



> Now, all things of the same type have the same set
> of magic routines, but that's not the same thing. (And you can attach
magic
> to the string "foo", though attaching magic to string constants requires
> doing some evil things...)
>

Indeed I can attach it, but it gets away as soon as I try to store it in a
variable, so it's useless, in this sense. And the kind of magic I was
wanting to attach to a string was the overloading kind, so that I can have a
string "foo" stored in a variable $x and overload its + operation so that it
concatenates (I know this example sucks, but you get the idea).

- Branden

Reply via email to