My task is to calculate list of all the primes between a and b using macro do-primes and then print them using the custom code.
Say (do-primes (n 5 15) (fresh-line) (princ n)) should print following 4 lines:
- 5
- 7
- 11
- 13
Here is my code:
(defun is-prime (n &optional (d (- n 1))) (or (= d 1) (and (/= (rem n d) 0) (is-prime n (- d 1))))) (defun my-func (a b) (let (lst '()) (loop for i from a to b do (if (is-prime i) (push i lst) ) ) (reverse lst)) ) (defmacro do-primes ((var startv endv) &body body) `(my-func ,startv ,endv) `(,@body) ) (do-primes (n 5 15) (fresh-line) (princ n)) But, when I run the code I have this error:
EVAL: (FRESH-LINE) is not a function name; try using a symbol instead
Any ideas how to make this code work properly?