列出的int我有一个像“乐趣,ARG1,ARG2” <线 - 它是一个字符串转换字符串列表Common Lisp中
我用“”分隔这个字符串分割成字符串列表。然后我将“fun”与一些字符串(例如“Fibonacci”)进行比较。
功能的分裂(正常工作)
(defun split-str (string &optional (r nil))
(let ((n (position "," string
:from-end t
:test #'(lambda (x y)
(find y x :test #'string=)))))
(if n
(split-str (subseq string 0 n)
(cons (subseq string (1+ n)) r))
(cons string r))))
测试功能
(defun tmp (a)
(if (string= (nth 0 a) "Fibonacci")
(progn
(setf tab '())
(dolist (n (cdr a))
(cons tab '(parse-integer n))) ; parsing works fine (checked with write)
(write tab)) ; always NIL
;(apply #'parse-integer (apply #'values a)) - doesn't work
(write "nok")))
呼叫:
(tmp (split-str "Fibonacci,15,33"))
为什么我的标签还没有2元?
请显示包含正确拆分的输出轨迹,并显示您在选项卡中获得的内容。有关准则,请参阅http://stackoverflow.com/help/mcve和其他介绍性帮助文档。 – Prune
请[请正确格式化您的代码](https://google.github.io/styleguide/lispguide.xml#Formatting)。 – sds
打开你的REPL并输入'(setf tab'())'''(cons tab 2)','tab'。想想几分钟的结果。然后在你的好书中阅读清单的介绍。 – molbdnilo