I am very new to LISP and was working through some beginner problems. I tried defining an ISPRIME function but it doesn't seem to be working correctly. Here is my code:
(defun ISPRIME (n &optional (d (- n 1)))
(if (= d 0)
( return-from ISPRIME t ))
(if (= (mod n d) 0)
( return-from ISPRIME nil ))
(ISPRIME n (- d 1)))
But upon running my code I use the value 5 as an example:
(ISPRIME 5)
Nil
5 should be a prime number. I suspect that everything is falling into the: (if (= (mod n d) 0) statement when it shouldn't be. d should continue to decrement until reaching 0 and returning true, yet it doesn't. I can't seem to see where my logic error is occuring.
Any and all help is greatly appreciated!