Quantcast
Channel: lisp service
Viewing all articles
Browse latest Browse all 20

How to convert a string to a float in Common Lisp

$
0
0

Since it took me more than a few minutes of googling to figure this out, I thought I'd post what I found. I found this parse-float function, which made me think that there wasn't a way to do it otherwise, but that turned out not to be the case. I learned here that all I needed was READ-FROM-STRING. As in:

* (read-from-string "#X23")
35
4
* (read-from-string "4.5")
4.5
3
* (read-from-string "6/8")
3/4
3
* (read-from-string "#C(6/8 1)")
#C(3/4 1)
9
* (read-from-string "1.2e2")
120.00001
5
* (read-from-string "symbol")
SYMBOL
6
* (defparameter *foo* 42)
*FOO*
* (read-from-string "#.(setq *foo* \"gotcha\")")
"gotcha"
23
* *foo*
"gotcha"

Permalink | Leave a comment  »


Viewing all articles
Browse latest Browse all 20

Trending Articles