On Friday, June 13, 2003, at 10:26 PM, David Storrs wrote:
On the subject of untyped scalars...what does it mean to say that the
conversion is 'lossless'?  For example:

I've been using the word to mean that a conversion is "lossless" if, for a particular A-->B conversion, you can recreate the typed value A *completely* from B, including value, definedness, and properties.


So if you can say A-->B-->A, and always get _exactly_ the same thing in A that you started with, for _any_ valid starting value of A, it's "lossless". Which is darn rare, looking at the matrix, because of range issues, etc.

   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>. (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.)



   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


In the above, I would expect that $c is 0 and

   my     $a = 7 but false;
   my Str $b = $e;      # ???

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.


Are any warnings emitted?

Yeah, I dunno. I think we need somebody smart to tell us at this point. I have no idea how close or how far we are on our musings about pragmas and defaults... I sure hope somebody does. :-)


MikeL



Reply via email to