Serge D. Mechveliani wrote:
> 
> People,
> 
> Please, what is the simplest (and fast) operation in the Axiom
> (Spad) library to parse  NonNegativeInteger from a  String of digits? 
> For example,
>              "201" -> 201   : NonNegativeInteger
> 
> I mean only this simplest syntax, which allows fast parsing.

If you know that the string contains correct integer, then
READ_-FROM_-STRING(s)$Lisp will work.  AFAIK there is no
Spad level operation to do directly parse integer.  Probably
the simplest Spad level way is:

integer(convert(parse(s)$InputForm)@SExpression)

However, this will first run FriCAS parser (which you apparently
want to avoid), then after determining that string forms
a number FriCAS parser will call READ_-FROM_-STRING and
return the result as InputFrom.  'convert' in this particular
case is no-op, just changing type without any change to
data.  Similarely, 'integer' is almost a no-op: it will
check that argument really is an integer, sugnal error
if not, othewise return argument with no change to data.

Note: currently READ_-FROM_-STRING is _the_ way in which
strings gets converted to integers.  If you want anything
faster you would need to work with character codes directly.
And to have any chance of beeing faster you would need to
use SingleInteger when it is enough.  Integer has arbitrary
precision and even if number is quite small Integer
operations pay overhead of function calls.  SingleInteger
has range which is restricted to what single machine
word can represent and operations on SingleInteger
typically can be done by few machine instructions
(sometimes one instruction, but in memory SingleInteger
has few bits for tagging which may need special handling
by extra machine instructions).

Note2: As I explained READ_-FROM_-STRING can do much more
than converting integers to strings.  Due to this universality
there is a per-call setup overhead.  So in general it is faster
to let READ_-FROM_-STRING handle larger piece of data than
use it many time on small pieces.

-- 
                              Waldek Hebisch
[email protected] 

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to