At 11:12 AM -0500 2/13/02, Buddha Buck wrote:
>At 03:43 PM 02-13-2002 +0000, Dave Mitchell you wrote:
>>Dan Sugalski <[EMAIL PROTECTED]> wrote:
>>> >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.
>>
>>Thanks.
>>I just want to assert/clarify that the job of "becoming whatever's
>>assigned to it" is delegated to the src PMC, since $plain won't itself know
>>how to do this?
>
>I assumed that the logic for assigning PMC to PMC would be something like:
>
>if (destPMC is specified as typeX) {
> if (srcPMC ISA typeX) {
> destPMC <- srcPMC
> } else {
> destPMC <- typeX.convert(srcPMC);
> }
>} else {
> destPMC <- srcPMC
>}
>
>in pseudocode form.
Right, for typed variables. Most variables (i.e. anything you
declared with a plain "my $foo" or "our @bar") are untyped and can
change their types as needed.
If you did:
my $foo;
$foo = Dog.new();
$foo = FireHydrant.new();
$foo would first be a Dog, then a FireHydrant. When it changed to a
FireHydrant the previous contents would get blown away.
>If we assume that there is a universal "root" type such that all
>PMC's are ISA typeRoot, and that typeX.convert(PMCofTypeY) is
>trivial if typeY ISA typeX, then this simplifies to
>
> destPMC <- destPCM.declaredtype.convert(srcPMC);
>
>Why does that look too simple?
Because I don't think we can assume a universal root, at least not
for the engine. For perl, sure, but not for parrot. Besides you hit
combinatorial explosion there pretty fast.
--
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
[EMAIL PROTECTED] have teddy bears and even
teddy bears get drunk