Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Coercion of non-numerics to numbers

4 views
Skip to first unread message

Dave Whipp

unread,
Mar 5, 2007, 12:22:59 PM3/5/07
to perl6-l...@perl.org
I was wondering about the semantics of coercion of non-numbers, so I
experimented with the interactive Pugs on feather:

pugs> +"42"
42.0
pugs> +"x42"
0.0

I assume that pugs is assuming "no fail" in the interactive environment.
However, Is "0.0" the correct answer, or should it be one of "undef", or
"NaN"?


In my experiments, I also noticed:

pugs> my Int $a = "42"
"42"
pugs> $a.WHAT
::Str


It seems that the explicit type of $a is being ignored in the
assignment. Am I right to assume this is simply a bug?

testcase (if someone with commit bits can add it):

{
no fail;
my Int $a = "not numeric";
is $a.WHAT, ::Int, "coercion in initial assignment";
}

Larry Wall

unread,
Mar 5, 2007, 8:18:54 PM3/5/07
to perl6-l...@perl.org
On Mon, Mar 05, 2007 at 09:22:59AM -0800, Dave Whipp wrote:
: I was wondering about the semantics of coercion of non-numbers, so I
: experimented with the interactive Pugs on feather:
:
: pugs> +"42"
: 42.0
: pugs> +"x42"
: 0.0
:
: I assume that pugs is assuming "no fail" in the interactive environment.
: However, Is "0.0" the correct answer, or should it be one of "undef", or
: "NaN"?

It should probably warn by default since warnings are supposed to be on
by default in Perl 6, but if that is supressed the return value should
at least be an interesting value of undef containing the warning that
would have been emitted, so that the warning can be issued later if
the value is actually used.

: In my experiments, I also noticed:


:
: pugs> my Int $a = "42"
: "42"
: pugs> $a.WHAT
: ::Str
:
:
: It seems that the explicit type of $a is being ignored in the
: assignment. Am I right to assume this is simply a bug?

Well, it's just not implemented, I think. Or more accurately, still in
the process of being implemented, since the pugsers are madly working on
metaobjects this week.

: testcase (if someone with commit bits can add it):

I'm sending you a commit bit so you can add tests. It's traditional
to add yourself to AUTHORS as the first checkin to make sure things work.

Larry

0 new messages