【发布时间】:2016-04-09 03:40:39
【问题描述】:
试图将函数和列表传递给函数。尝试将列表中的每个项目与以下项目进行比较。
功能是:
(defun my-list-function(fn L)
(if (< (length L) 2)
(message "List needs to be longer than 2")
(progn (setq newL L) ;; Save the list locally
(while (> (length newL) 1) ;; While list has 2 items
(setq t (car newL)) ;; Get first item
(setq newL (cdr newL)) ;; resave list minus first item
(funcall #'fn t #'car newL))))) ;; pas first two items to a function
我不断收到错误 - 设置常量-t
【问题讨论】:
-
当你想在一个函数中拥有一个局部变量时,你通常在使用它之前将它与
let绑定。在这个代码示例中,newL实际上变成了一个全局变量。