Google グループは Usenet の新規の投稿と購読のサポートを終了しました。過去のコンテンツは引き続き閲覧できます。
Dismiss

Coercion of non-numerics to numbers

閲覧: 4 回
最初の未読メッセージにスキップ

Dave Whipp

未読、
2007/03/05 12:22:592007/03/05
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

未読、
2007/03/05 20:18:542007/03/05
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 件