The value of +"hello"

0 views
Skip to first unread message

Daniel Brockman

unread,
Aug 14, 2005, 9:48:22 AM8/14/05
to perl6-l...@perl.org
Exegesis 3 contains this snippet,

my $inflation;
print "Inflation rate: " and $inflation = +<>
until $inflation != NaN;

but the rule that +"hello" evaluates to NaN is "no longer"
mentioned in S03, according to Autrijus.

He suggested I post here to get a ruling.

--
Daniel Brockman <dan...@brockman.se>

Larry Wall

unread,
Aug 16, 2005, 1:25:52 PM8/16/05
to perl6-l...@perl.org
On Tue, Aug 16, 2005 at 10:00:14AM -0700, Larry Wall wrote:
: If we go with class names being the undefined prototypical values,
: and if we assume that NaN is an "unthrown exception" variant of
: the undefined value for object types like Num, then we might even
: end up with Num == NaN, albeit with different exception information
: hidden inside. Num is "not yet defined", whereas NaN is "tried to
: convert 'hello' to number at inflate line 2" or some such.

I forgot to point out that you naturally lose that extra exception
information when you store a Num into a num. Whether that warns or
throws an exception or is silent is likely controlled by pragma.
People doing complicated things with large matrices might prefer
silence, whereas people doing scalar ops will usually prefer to know
that something went wrong sooner, and not have to backtrace through
the code to figure out where the NaN was generated. But maybe most
of that naturally falls out of the num/Num distinction, since num
will mostly be used in compact arrays.

Larry

Larry Wall

unread,
Aug 16, 2005, 1:00:14 PM8/16/05
to perl6-l...@perl.org
On Sun, Aug 14, 2005 at 03:48:22PM +0200, Daniel Brockman wrote:
: Exegesis 3 contains this snippet,

:
: my $inflation;
: print "Inflation rate: " and $inflation = +<>
: until $inflation != NaN;
:
: but the rule that +"hello" evaluates to NaN is "no longer"
: mentioned in S03, according to Autrijus.
:
: He suggested I post here to get a ruling.

I'm not sure it ever was mentioned in S03, but we'd like to stick as
close as we can to IEEE floating point, and that includes NaN as
a value that can be stored not only in a Num but also in a num.
(Along with +Inf and -Inf). I suppose machines that don't do IEEE
floating point will have to emulate num with Num.

If we go with class names being the undefined prototypical values,
and if we assume that NaN is an "unthrown exception" variant of
the undefined value for object types like Num, then we might even
end up with Num == NaN, albeit with different exception information
hidden inside. Num is "not yet defined", whereas NaN is "tried to
convert 'hello' to number at inflate line 2" or some such.

Larry

Reply all
Reply to author
Forward
0 new messages