On Mon, Jun 16, 2003 at 10:15:57AM -0700, Michael Lazzaro wrote: > > On Friday, June 13, 2003, at 10:26 PM, David Storrs wrote: > > > my $a = 'foo'; > > my Int $b = $a; # legal; $b is now 0; is there a warning? > > my $c = $b; # is $c 0, or 'foo'? > > 0, I think. Or specifically, C<Int 0>.
So then conversion from Scalar to Int is not lossless, and (by extension) conversions from Scalar to any other LargeCapPrimitive are presumably not lossless either. > (I've been operating under the > assumption that an "untyped scalar" doesn't _remove_ the type of > something, it just can store values of _any_ type, and is by default > much more generous about autoconverting them for you, so that you could > use $c as an Int, int, Num, num, Str, str, etc., without warning or > error... but internally, it's actually still storing the value as an > C<Int 0>, because that's what you assigned to it.) Seems reasonable. <pedantic> Although I would assume that it would store and pull the value from an Int slot, then create a new value of the "converted to" type, and use that. </pedantic> > > my Str $d = $a; # no loss > > my $a = $d; # no effective change in $a > > my $e = $b; # what is $d? > > $d? Still a Str, I would think. And $e would be Int 0, same as $c I obviously had either a typo or a braino on the last line there. I have no idea what I was trying to ask. > > What value does $f end up with? (My vote would be '7'.) > > My understanding is that properties go with the values, (just like > traits go with the variables), so I would expect $f to be C<7 but > false>. So if a value is C<but false>, it stays C<but false> until you > say otherwise. A better example of what I was driving at would be this: my $a = 'foo' but purple; my Int $b = $a; In other words: I've just created an untyped Scalar. This Scalar is (presumably in it's Str slot) storing a string value which happens to have a property set on it (i.e., C<foo but purple). Now I assign this Str to an Int. String values get converted when assigned to Ints. Are we converting and assigning THE IDENTICAL VALUE or are we creating a new value (whose value, in a numeric context, is considered equivalent) and assigning that? In the first case, I would expect that the property would be preserved. In the latter case, I would expect it NOT to be preserved. --Dks OT afterthought: In the past, whenever we've gotten embroiled in one of these thorny, knotty issues, @Larry has pulled a stunningly beautiful, elegant rabbit out of their hats. And when I thought that, I had this vision of a single quantum rabbit simultaneously coming out of multiple hats with widely divergent spatial coordinates....