Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Coercion of non-numerics to numbers

已查看 5 次
跳至第一个未读帖子

Dave Whipp

未读,
2007年3月5日 12:22:592007/3/5
收件人 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

未读,
2007年3月5日 20:18:542007/3/5
收件人 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 个新帖子