Starting with abo-abo's version, you can simplify a lot:
1) get rid of (= X Y) and replace (list nil) by nil in (> X Y)
(defun xtoy (X Y)
(cond ((> X Y) nil)
(t (append (list X) (xtoy (+ 1 X) Y)))))
2) simplify cond
to an if
statement
(defun xtoy (X Y)
(if (<= X Y)
(append (list X) (xtoy (+ 1 X) Y))
nil))
3) leave out the final nil
, because that's what's implicitly returned when the condition doesn't match
(defun xtoy (X Y)
(if (<= X Y)
(append (list X) (xtoy (+ 1 X) Y))))
4) use cons
instead of append
(defun xtoy (X Y)
(if (<= X Y)
(cons X (xtoy (+ 1 X) Y))))