How can i convert the string "1 2 3 4 5 6 7"
into the list (1 2 3 4 5 6 7)
elegantly? I am using CLISP.
Strings can be converted to lists using list() .
Lists are single linked lists. In LISP, lists are constructed as a chain of a simple record structure named cons linked together.
To compare the characters of two strings, one should use equal, equalp, string=, or string-equal. Compatibility note: The Common Lisp function eql is similar to the Interlisp function eqp.
Here is a recursive solution.
;Turns a string into a stream so it can be read into a list
(defun string-to-list (str)
(if (not (streamp str))
(string-to-list (make-string-input-stream str))
(if (listen str)
(cons (read str) (string-to-list str))
nil)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With