Re: ISA number

2000-08-08 Thread Ken Fox

Peter Scott wrote:
 Have often wanted a way to tell whether a scalar was a number

 way to get at the SvIOK and SvNOK results would be great.

SvIOK, SvNOK and "is a number" are not the same thing at all.
Often numbers are strings that just look like numbers. Perl doesn't
eagerly convert stuff into numbers -- it waits until it needs to.

For example:

if (/(\d+)/) {
  ...
}

$1 is not SvIOK, but it is definitely a number. I seriously
doubt if Perl 6 is going to change this behavior (if it ain't
broken don't fix it...)

IMHO, the language shouldn't know about SvIOK etc. Perhaps
ref() can be supplemented with a typeof() function taking one
or two args. typeof($s) would just return the type of $s.
typeof($s, 'integer') could check to see if $s is coercible
to integer.

- Ken



Re: ISA number

2000-08-07 Thread Hildo Biersma

Peter Scott wrote:
 
 Have often wanted a way to tell whether a scalar was a number, and rolling
 a regex each time seemed wasteful given that Perl knew what it was
 anyway.  So a user-friendly way to get at the SvIOK and SvNOK results would
 be great.
 
 The pedestrian way would be a builtin: isnum() or similar.  But we have
 enough creativity here I'm sure we can come up with something far more
 obfusc^Wconcise :-)

Agree here.  I've seen people resort to DBI.pm's 'looks_like_number' or
using tricks like ($a + 0 eq $a), but really this should be easier. 
Having said that, it doesn't need to live in the core - and even today
it should be relatively easy to write an XS module for this.

Hildo



Re: ISA number

2000-08-07 Thread John Porter

Peter Scott wrote:
 Have often wanted a way to tell whether a scalar was a number, ...
 So a user-friendly way to get at the SvIOK and SvNOK results would 
 be great.

This is one of those rare proposals which can safely be assumed to
be proposed, discussed, and accepted without dissent -- before the RFC
is even issued!

-- 
John Porter




Re: ISA number

2000-08-07 Thread Dan Sugalski

At 12:27 PM 8/7/00 -0700, Peter Scott wrote:
Have often wanted a way to tell whether a scalar was a number, and rolling 
a regex each time seemed wasteful given that Perl knew what it was 
anyway.  So a user-friendly way to get at the SvIOK and SvNOK results 
would be great.

The Sv?OK macros will likely go away in the new internals, or at least be 
different. It'd be better to figure out what you really want to know. Those 
macros tell you whether a scalar has already been changed to an integer, 
float, or string, rather than whether it can be an int, float, or string, 
for example.

Dan

--"it's like this"---
Dan Sugalski  even samurai
[EMAIL PROTECTED] have teddy bears and even
  teddy bears get drunk