我是普通lisp的初学者。
如果我的号码是123456890并且我想分别得到数字1 2 3 5 9,我该如何在常见的lisp中进行操作?
答案 0 :(得分:0)
首先,很明显,这个问题在多次解决之前就已经解决了,你必须在问之前搜索解决方案,因为否则你会让其他人更难找到一个好的解决方案。所以,这是一个较旧的答案:Coercing numbers to lists in common lisp
(defun int-to-list (int)
(assert (>= int 0) nil "Argument must be non-negative")
(if (= int 0) (list 0)
(loop with result = nil
while (> int 0) do
(multiple-value-bind (divisor remainder)
(floor int 10)
(push remainder result)
(setf int divisor))
finally (return result))))