我对这里的一个小问题感到疯狂,我不断收到错误,我似乎无法弄清楚为什么,代码应该改变列表的范围,所以如果我们给它一个带有值的列表(1 2 3 4)
并且我们想要将范围从 11 更改为 14 结果将是(11 12 13 14)
问题是最后一个调用的函数scale-list
将返回一个错误说:
调试器进入--Lisp 错误:(错误类型参数编号-或标记-p nil)
有人知道为什么吗?我使用 aquamacs 作为编辑提前谢谢
;;finds minimum in a list
(defun minimum (list)
(car (sort list #'<)))
;;finds maximum in a list
(defun maximum (list)
(car (sort list #'>)))
;;calculates the range of a list
(defun range (list)
(- (maximum list) (minimum list)))
;;scales one value to another range
(defun scale-value (list low high n)
(+ (/ (* (- (nth (- n 1) list)
(minimum list))
(- high low))
(range list))
low))
;;is supposed to scale the whole list to another range
(defun scale-list (list low high n)
(unless (= n 0)
(cons (scale-value list low high n)
(scale-list list low high (- n 1)))))
(scale-list '(1 2 3 4) 21 24 4)