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

String -> Numeric conversion

1 view
Skip to first unread message

Luke Palmer

unread,
Nov 6, 2002, 6:00:24 PM11/6/02
to mlaz...@cognitivity.com, perl6-l...@perl.org
> Mailing-List: contact perl6-lan...@perl.org; run by ezmlm
> Date: Wed, 6 Nov 2002 14:53:37 -0800
> From: Michael Lazzaro <mlaz...@cognitivity.com>
> X-SMTPD: qpsmtpd/0.12, http://develooper.com/code/qpsmtpd/
>
>
> If anyone knows the answer to these two questions, I'd appreciate it.
>
> 1) What do these do?
>
> my int $n = 5; # OK
> my int $n = 5.005; # trunc or err?

Trunc. Int context, you know :)

> my int $n = "5.05ff" # 5, 0, undef, NaN, or exception?

If it's like Perl5, 5.05. But there could be reason to make it an
exception. Dunno on that one. I would say 5.05 for now, until
someone with authority corrects it.

> my int $n = "fdsjfdf" # 0, undef, NaN, or exception?

Likewise here. There could also be reason to have this behave
differently from the last one. Though, I would say 0 for now.

>
> 2) Do "num" and "int" share a common base "is a number" class, such
> that (in perl5-ish speak) we can say
>
> if want(numeric) { ... }
>
> to identify both, or is "num" the base class to test for, and "int" a
> subclass? (I'm pretty much assuming "bit" is a number too, but never
> mind that now.)

I believe this was the plan. Remember, there was int context and num
context, so a natural extension would be that conclusion.

As for your documentation plan, I think it's a good idea, though I
concur with Dan on Just Do It. Document the language for what best
makes sense now. If there are *big* issues, ask Larry et al. on this
list. For the little ones, use common sense and they will be hashed
out later.

Luke

Michael Lazzaro

unread,
Nov 6, 2002, 5:53:37 PM11/6/02
to perl6-l...@perl.org

If anyone knows the answer to these two questions, I'd appreciate it.

1) What do these do?

my int $n = 5; # OK
my int $n = 5.005; # trunc or err?

my int $n = "5.05ff" # 5, 0, undef, NaN, or exception?

my int $n = "fdsjfdf" # 0, undef, NaN, or exception?

2) Do "num" and "int" share a common base "is a number" class, such
that (in perl5-ish speak) we can say

if want(numeric) { ... }

to identify both, or is "num" the base class to test for, and "int" a
subclass? (I'm pretty much assuming "bit" is a number too, but never
mind that now.)

I know that this has been covered before, way back, but my memory fails
me. Just trying to polish up what I wrote.

MikeL

Piers Cawley

unread,
Nov 6, 2002, 7:39:15 PM11/6/02
to Luke Palmer, mlaz...@cognitivity.com, perl6-l...@perl.org
Luke Palmer <fibo...@babylonia.flatirons.org> writes:

>> Mailing-List: contact perl6-lan...@perl.org; run by ezmlm
>> Date: Wed, 6 Nov 2002 14:53:37 -0800
>> From: Michael Lazzaro <mlaz...@cognitivity.com>
>> X-SMTPD: qpsmtpd/0.12, http://develooper.com/code/qpsmtpd/
>>
>>
>> If anyone knows the answer to these two questions, I'd appreciate it.
>>
>> 1) What do these do?
>>
>> my int $n = 5; # OK
>> my int $n = 5.005; # trunc or err?
>
> Trunc. Int context, you know :)
>
>> my int $n = "5.05ff" # 5, 0, undef, NaN, or exception?
>
> If it's like Perl5, 5.05. But there could be reason to make it an
> exception. Dunno on that one. I would say 5.05 for now, until
> someone with authority corrects it.
>
>> my int $n = "fdsjfdf" # 0, undef, NaN, or exception?
>
> Likewise here. There could also be reason to have this behave
> differently from the last one. Though, I would say 0 for now.

Well, it's restricted to either 0 or an exception since you can't use
an int to store anything else (like, for instance the PMCs associate
with either undef or NaN).

Hmm, what does

NaN.isa('Number')

return?

--
Piers

"It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite."
-- Jane Austen?

Damian Conway

unread,
Nov 7, 2002, 4:54:17 AM11/7/02
to perl6-l...@perl.org
Michael Lazzaro wrote:
>
> If anyone knows the answer to these two questions, I'd appreciate it.

Only Larry "knows". But I'm prepared to take an educated guess.


> 1) What do these do?
>
> my int $n = 5; # OK

Yes.


> my int $n = 5.005; # trunc or err?

Truncate to 5 with optional warning (would be my preference).


> my int $n = "5.05ff" # 5, 0, undef, NaN, or exception?

Truncate to 5 with optional warning (would be my preference).


> my int $n = "fdsjfdf" # 0, undef, NaN, or exception?

Call C<fail> would be my preference.
That is, let the user decide whether the result is C<undef> or an exception.


> 2) Do "num" and "int" share a common base "is a number" class, such that
> (in perl5-ish speak) we can say
>
> if want(numeric) { ... }
>
> to identify both, or is "num" the base class to test for, and "int" a
> subclass?

The latter would be my expectation. Though it's C<Num>, not c<num>, I believe.

Damian

0 new messages