3

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 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Check out the Guide in Racket:

http://docs.racket-lang.org/guide/read-write.html?q=read

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.