Schematic: Parsing a String

I want to convert a string "(1 2 3 4)"to a list (1 2 3 4).
How can this be done using a circuit?

+3
source share
2 answers

You can use the built-in function readby turning the string into an "input port" (abstraction of a file open for reading):

(read (open-input-string "(1 2 3 4)")) ;; evaluates to (1 2 3 4)

This works in both Guile and Racket. Depending on the implementation of the circuit, you may also need to import the SRFI-6 module .

+4
source
0
source

All Articles