* demerphq <demerphq@gmail.com> [2013-05-06 12:15]: > On 6 May 2013 12:02, Dave Mitchell <davem@iabyn.com> wrote: > >On Sun, May 05, 2013 at 11:45:25PM +0200, Sébastien Aperghis-Tramoni wrote: > >>So, here is a proposal to try making this situation a bit better: > >>annotate the SV to record the initial (or canonical) type of the the > >>value, that is the type of the value that was last affected to the > >>SV. > > > >But I don't think that necessarily solves the problem. Consider: > > > > while (<DATA>) { > > chomp; > > my ($x,$y) = split / /, $_; > > my $z = sqrt($x*$x + $y*$y); > > ... serialise $x, $y, $z; > > } > > __DATA__ > > 0.123 1.234 > > ... > > > >should $x, $y be serialised as strings or floats? I think the desire > >of the programmer would be for them to be floats, but the canonical > >form is string. In other words, the initial type still doesn't > >necessarily DWIM, and its still up to the programmer to manually > >ensure the output is as desired. > > Personally i think most serialization module authors would consider > the canonical form to be the string, not the NV. > > Consider what should happen if the data line was > > __DATA__ > 0.123x 0.1234x But under Sébastien’s suggestion, $x and $y *would* have their string form considered canonical. The only variable that would not is $z. Or to put it in other words: the non-string forms would be considered canonical only if the string form was derived from them, i.e., only if the string form has at most equal fidelity to the chosen form. Can you come up with any example were initial type annotation would make the fidelity of the data worse? I *can* come up with one example for the case of always considering the string form canonical: converting floats to strings can be lossy. So the string form is *not* always the highest-fidelity form of the data. As far as I can reason, picking the canonical form of a value based on its initial type can never make the fidelity worse. Is that false? Regards, -- Aristotle Pagaltzis // <http://plasmasturm.org/>Thread Previous | Thread Next