   (cond
     (number? expr) 0
     (symbol? expr) (if (= expr var) 1 0)
-    (sum? expr) (list* '+ (map  #(derivative % var) (rest expr)))
-    (prod? expr) (list* '+ (derivative-prod (rest expr) var))
+    (sum? expr) (make-sum (map  #(derivative % var) (rest expr)))
+    (prod? expr) (make-sum (derivative-prod (rest expr) var))
     ))
 
 ;; ---------------------------------------------------------------

  [expr]
  (or
    (= (first expr) '*) ;; Works with simple quote
    (= (first expr) `*) ;; Works with ` quote
    ))

(defn sum?
  [expr]
  (or
    (= (first expr) '+) ;; Works with simple quote
    (= (first expr) `+) ;; Works with ` quote
    ))

(declare derivative)

(defn derivative-prod
  [terms var]
  (for [r (rotations terms)]
    (list* '* (derivative (first r) var) (rest r))
    ))

(defn derivative

  (prn (derivative 'x 'x))
  (prn (derivative 'x 'y))
  (prn (derivative `x `x))
  (println "------------------")
  (prn (make-sum ['x 'y]))
  (prn (make-sum [1 2 3]))
  (prn (make-sum [1 0 'x 5 'y]))
  (println "------------------")
  (prn (make-product ['x 'y]))
  (prn (make-product [1 'x 0]))
  (prn (make-product [2 'y 'x 5]))
  (println "------------------")
  (prn (derivative (list '+ 'x 1) 'x))
  (prn (derivative `(+ x 1) `x))
  (prn (derivative `(* x 2) `x))
  (println "------------------")
  (prn (derivative `(+ x (* x x y)) `x))
  )

