gpt4 book ai didi

lisp - 如何使用 clisp 将字符串转换为列表?

转载 作者:太空宇宙 更新时间:2023-11-03 18:35:32 27 4
gpt4 key购买 nike

如何优雅地将字符串 "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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com