(defun pCount (number)
  (let (ans 0)
    (do ((iterator 1 (+ iterator 2)))
    ((equal iterator number))
    (if (equal (0) (rem iterator 3)))
        (+ ans iterator)
        (if (equal (0) (rem iterator 5)))
        (+ ans iterator)
        (+ ans 0))))

The object is to find the sum of all numbers divisible by 3 or 5 that are less than or equal to the number fed to the function.
(Problem from the site www.projecteuler.net)

As someone who is still new to the Lisp compiler error messages,

"While compiling pCount :
0 is not a symbol."

this looks like "equal" doesn't like the fact that I'm testing whether something is equal to a lone number, 0 in this case.

Is this the right analysis? And if so, why can I not put a number there?
Is there anything else terribly wrong with the code above?


Edited by mike_2000_17: Fixed formatting

6 Years
Discussion Span
Last Post by jon.kiparsky

I am (attempting) using Common Lisp. Changed "equal" to "=" for no effect.


Oh, I'm a moron. (0) is the problem - you want just 0, with the parens it means "the function of no argument called "0"

Here's some evaluations:

[1]> (= 2 4)
[2]> (= 2 2)
[3]> (= (0) 1)

*** - EVAL: 0 is not a function name; try using a symbol instead
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead.
ABORT          :R2      Abort main loop
Break 1 [4]> (= 0 1)
Break 1 [4]>

Looks like equal will work as well - I don't know if clisp makes a distinction, I'll play around and see. (I haven't done a lot of common)

Edited by jon.kiparsky: n/a


Switched all the (0)'s to 0's. My compiler still insists that I'm using 0 as a symbol and that I'm not allowed to. (Error message above)


Ah. Now I feel dumb. It accepted the 0's, but more errors await. Next is the fact that my if statements are screwy somehow. Thanks for the help, though!


Okay, good. I was just getting ready to open up an interpreter.

The solution you're using looks like a reasonable one, although you should consider what happens when it hits 15 or 45. That's just a glance over it, though, there may be booby traps I haven't spotted. Good luck.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.