Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Me being a bad common lisp beginner

Name: sage 2010-12-06 17:54


(defun problem-5 (n i)                                   
  (cond                                                   
   ((< i 20) (if (equalp (mod n i) 0)                   
                        (problem-5 n (+ i 1))           
                        ((setq i 1) (problem-5 (+ n 1) i))))
   ((equalp i 20) (print n))))

The error is in the (setq i 1) line, it's an illegal function call but I can't see what I'm doing wrong.

Name: Anonymous 2010-12-06 18:06


((setq i 1) (problem-5 (+ n 1) i)


You're trying to call the result of (setq i 1) with the result of (problem-5 (+ n 1) i) as argument.

It should be
(progn (setq i 1) (problem-5 (+ n 1) i))

But setting a variable, passing it to a function and forgetting it is nonsensical, you can just do (problem-5 (+ n 1) 1)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List