nakias wrote:Hey
I need your help for a program in common lisp. The program has to do with polynomial manipulation.
My problem is when i do simple arithmetic operations does not accept any letters e.g (p+ x 4)
(defun p+ (p1 p2)
(list '+ p1 p2))
(defun p+ (p1 p2)
(+ p1 p2))
How can i make it in order to accept letters as well ?
Thanks in advance
p+ is a function which means it gets its arguments evaluated. 4 evaluates to itself, but x would evaluate to what ever x is bound to, which looks like nothing in this case. To prevent evaluation of an object you quote it; (quote x) would be the quoted form of x. Because quoting is so common, you have a read macro to do it automatically, and so you can just write 'x
Now then while (list '+ 'x 4) makes sense, (+ 'x 4) does not because 'x is not a number, so only your first definition for p+ would work with (p+ 'x 4)