a question on common lisp
- by kostas
Hello people,
I'm getting crazy with a small problem here,
I keep getting an error and I cant seem to figure out why,
the code is supposed to change the range of a list,
so if we give it a list with values (1 2 3 4) and we want to change the range in 11 to fourteen the result would be (11 12 13 14)
the problem is that the last function called scale-list will give back an error saying:
Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
anybody has a clue why?
I use aquamacs as an editor
thanks in advance
;;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)))
;;this codes scales a value from a list
(defun scale-value(list low high n)
(+ (/ (* (- (nth (- n 1) list) (minimum list)) (- high low)) (range list)) low))
;and this code is supposed to scale the whole list
(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 '(0.1 0.3 0.5 0.9) 20 30 4)