Reputation: 1193
I want to convert a string "(1 2 3 4)"
to a list (1 2 3 4)
.
How can this be done using Scheme?
Upvotes: 3
Views: 1499
Reputation: 31147
Check out the Guide in Racket:
http://docs.racket-lang.org/guide/read-write.html?q=read
Upvotes: 0
Reputation:
You could use the built-in read
function by turning the string into an "input port" (an abstraction of a file opened for reading):
(read (open-input-string "(1 2 3 4)")) ;; evaluates to (1 2 3 4)
That works in both Guile and Racket. Depending on your Scheme implementation, you might also need to import the SRFI-6 module.
Upvotes: 5