login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Here is a package that converts strings to numbers. It is only to be considered as a starting point. There is no error checking, it is probably slow and certainly buggy...

fricas
)abbrev package STRCNV StringConversions
StringConversions(): Exports == Implementation where
    Exports == with
coerce: String -> Integer
coerce: String -> Fraction Integer
coerce: String -> List Fraction Integer
coerce: String -> List Integer
coerce: String -> Set Integer
Implementation == add
sexfloat:SExpression:=convert(coerce("Float")@Symbol)$SExpression
coerce(s: String): Fraction Integer == if not NUMBERP(READ_-FROM_-STRING(s)$Lisp)$Lisp then error "coerce: String -> Fraction Integer: not a number" else sex := interpret(packageTran(ncParseFromString(s)$Lisp)$Lisp)$Lisp if (car car sex = sexfloat) then retract((cdr cdr sex) pretend Float)@Fraction(Integer) else if integer?(cdr sex) then ((cdr sex) pretend Integer)::Fraction Integer else (cdr cdr sex) pretend Fraction Integer
coerce(s: String): Integer == PARSE_-INTEGER(s)$Lisp
coerce(r: String): List Fraction Integer == map(coerce #1, split(r, char(" "))$String)_ $FiniteLinearAggregateFunctions2(String, List String, Fraction Integer, _ List Fraction Integer)
coerce(r: String): List Integer == map(coerce(#1), split(r, char(" "))$String)_ $FiniteLinearAggregateFunctions2(String, List String, Integer, _ List Integer)
coerce(r: String): Set Integer == s: String := delete(delete(r, #r), 1) brace(map(PARSE_-INTEGER(#1)$Lisp, split(s, char(" "))$String)_ $FiniteLinearAggregateFunctions2(String, List String, Integer, _ List Integer))$Set(Integer)
fricas
Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1862277760152673546-25px.001.spad
      using old system compiler.
   STRCNV abbreviates package StringConversions 
------------------------------------------------------------------------
   initializing NRLIB STRCNV for StringConversions 
   compiling into NRLIB STRCNV 
   compiling exported coerce : String -> Fraction Integer
Time: 0.01 SEC.
compiling exported coerce : String -> Integer STRCNV;coerce;SI;2 is replaced by PARSE-INTEGER Time: 0.01 SEC.
compiling exported coerce : String -> List Fraction Integer Time: 0.03 SEC.
compiling exported coerce : String -> List Integer Time: 0 SEC.
compiling exported coerce : String -> Set Integer Time: 0.01 SEC.
(time taken in buildFunctor: 0)
;;; *** |StringConversions| REDEFINED
;;; *** |StringConversions| REDEFINED Time: 0 SEC.
Cumulative Statistics for Constructor StringConversions Time: 0.06 seconds
finalizing NRLIB STRCNV Processing StringConversions for Browser database: --->-->StringConversions(constructor): Not documented!!!! --->-->StringConversions((coerce ((Integer) (String)))): Not documented!!!! --->-->StringConversions((coerce ((Fraction (Integer)) (String)))): Not documented!!!! --->-->StringConversions((coerce ((List (Fraction (Integer))) (String)))): Not documented!!!! --->-->StringConversions((coerce ((List (Integer)) (String)))): Not documented!!!! --->-->StringConversions((coerce ((Set (Integer)) (String)))): Not documented!!!! --->-->StringConversions(): Missing Description ; compiling file "/var/aw/var/LatexWiki/STRCNV.NRLIB/STRCNV.lsp" (written 31 JUL 2013 07:03:42 PM):
; /var/aw/var/LatexWiki/STRCNV.NRLIB/STRCNV.fasl written ; compilation finished in 0:00:00.032 ------------------------------------------------------------------------ StringConversions is now explicitly exposed in frame initial StringConversions will be automatically loaded when needed from /var/aw/var/LatexWiki/STRCNV.NRLIB/STRCNV

Let's try it:

fricas
coerce("123.12")@FRAC INT

\label{eq1}{3078}\over{25}(1)
Type: Fraction(Integer)




  Subject:   Be Bold !!
  ( 13 subscribers )  
Please rate this page: