I want to convert a string "(1 2 3 4)" to a list (1 2 3 4).
How can this be done using Scheme?
2 Answers
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.