[PLUG] lisp: coerce string to real

Carlos Konstanski ckonstanski at pippiandcarlos.com
Sat May 31 18:16:57 UTC 2008


Any lispers out there (attn. Russ) who know a good way to coerce a
string (it's a given that the string is a representation of a legal
real value) to a real?  Common lisp provides (parse-integer) only.  I
think the following algorithm would work:

- split the string on the decimal point

- (parse-integer) the absolute value of the whole portion

- (parse-integer) the fractional portion

- divide that by the power of 10 that matches the number of decimal
  places to the right of the decimal point

- add that to the whole portion

- apply the sign of the original number

Is there a better way?

Carlos Konstanski



More information about the PLUG mailing list