如何优雅地将字符串 "1 2 3 4 5 6 7"
转换为列表 (1 2 3 4 5 6 7)
?我正在使用 CLISP。
最佳答案
这是一个递归的解决方案。
;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)))
关于lisp - 如何使用 clisp 将字符串转换为列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7459501/