At 10:48 AM +0000 2/13/02, Dave Mitchell wrote: >Dan Sugalski <[EMAIL PROTECTED]> wrote: >> #2 is what you get with normal assignment. $foo = $bar, for example. >> $foo's assign vtable method is called with $bar as a parameter. $foo >> figures out what it should do--if it's a tied variable of some sort >> it should perform its assign action. (This includes throwing an >> exception if the assignment isn't valid) Otherwise it should >> typecheck the RHS and morph itself into the RHS's type. > > >So in the following: > >my Complex $c = 3+4i; >my $plain = 1.1; >$plain = $c; > >I presume that $plain ends up as type Complex (with value 3+4i)?
Yup. >If so, how does $plain know how to "morph itself into the RHS's type"? The general rule is: If a PMC is not a fixed type, it tosses its contents and becomes whatever's assigned to it. If it is a fixed type, it extracts what it can as best it can from the source and uses that. In this case, $plain is a boring old scalar, so it becomes a Complex. If, later on, you assigned a string to it, it'd become a boring scalar with a string component. On the other hand, $c is a Complex, and you can't assign anything that's not a Complex or a subclass of Complex, to it. If you try, the destination gets from the source whatever it can that's useable. (There's a limited stock of things that can be chosen--various ints, floats, or strings) The compiler may also emit typechecking opcodes to pitch a fit when you try an incompatible assignment -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk