对Lisp来说是新手。尝试将列表传递到递归函数中,并每次对列表中的第一项执行操作。这是迄今为止的职能:
(setq colors '(red blue green yellow orange pink purple))
(defun my-function (x)
(if (> (length x) 0)
(let ((c (car x))
c)
(my-function x))))不断得到一个错误,说x是一个空元素。不知道该怎么做。
发布于 2016-03-25 04:30:26
如果我重新格式化你的函数,也许你会发现你做错了什么:
(defun my-function (x)
(if (> (length x) 0) ; do nothing if list is empty
(let ((c (car x)) ; bind c to (car x)
c) ; bind c to nil instead
; c is never used
(my-function x)))) ; recursively call function
; with unmodified x
; until the stack is blown不断得到一个错误,说x是一个空元素。
我猜想您是用一个未定义的(my-function x)来调用x,而不是将它作为colors列表传递给(my-function colors),但这肯定不是您唯一的问题。
https://stackoverflow.com/questions/36213460
复制相似问题