The inputs to poly
don't "need to be quoted". Instead of
(d '(+ x y) 'x)
you could write any of the following:
(d (list '+ 'x 'y) 'x)
(d (make-sum 'x 'y) 'x)
(let ((ex 'x) (why 'y))
(d (list '+ ex why) ex))
In your attempt in the question, you're trying to call d
with the result of (poly x)
which tries to call a function a named poly
(actually, the function binding of the symbol poly
, or some other possible things, but that's probably more in-depth than we need to get right now) with the value of the variable x
:
(defun differentiate (poly x)
;; call poly with the value of x to produce a value y, and
;; then call d with y to produce a value z, and then call
;; simplify with z.
(simplify (d (poly x))))
That won't work, of course, because there's no function named poly
, and even if there was, d
expects two arguments, not one. Instead, the first thing you should do is call d
with two arguments, viz., the values of the variables poly
and x
, and then call simplify with the result of that:
(defun differentiate (poly x)
(simplify (d poly x)))