I’m currently trying to learn lisp and am using emacs on linux. To the best of my ability, I have written two functions.
Both functions first remove the first element of the list.
seriesadds all the elements in the given list.parallel
1) takes the inverse of each number in the list, then
2) adds all the elements in the list, then
3) takes the inverse of the sum of the elements.
Code:
(defun series (lst)
(apply #'+' (cdr lst)) )
(defun parallel (lst)
(/ 1 (apply #'+' (apply #'/' (cdr 'lst ) ) ) ))
I can evaluate the function, but when I try to use the function, as below:
(series (list 3 3 4 5))
I get the error : value CDR is not of the expected type NUMBER.
I see this, and I think, why is emacs treating cdr as a number rather than a function?
I’m new to lisp and emacs, so I don’t know to fix this error. Any help would be appreciated.
UPDATE
I’ve the problems in this code and I think it works…
(defun series (lst)
(apply #'+ (cdr lst) ))
(defun parallel(lst)
(/ 1 (apply #'+ (mapcar #'/ (make-list (- (length lst) 1) :initial-element 1) (cdr lst) ) )))
Hopefully, what I was trying to do is understood now.
You have extra apostrophes that are confusing the LISP parser. The syntax to refer to the
+function is just#'+; there’s no “close quote”.