Lispy code? Sum multiples of 3 or 5 up to 1000 I've started learning Lisp one more time (I seem to do this every couple years); my experience is with C, basically. I attempted to solve the Project Euler problem 1:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

My solution to the problem is below.
Please suggest improvements, style changes, indentation, commenting, naming of &quot;objects&quot;, ...
(defun multiple-of-3-or-5p (n)
    &quot;predicate for multiple of 3 or 5&quot;
    (cond ((= 0 (rem n 3)) t)
          ((= 0 (rem n 5)) t)
          (t nil)))

(defun sum35 (n)
    &quot;sum all multiples of 3 or 5 up to n (including n)&quot;
    (cond ((= n 0) 0)
          (t (+ (if (multiple-of-3-or-5p n) n 0) (sum35 (- n 1))))))

;; in the repl use
;; (sum35 999)

(defun predicate-sum (predicate n)
    &quot;sum integers up to n (including n) that match the predicate&quot;
    (cond ((= n 0) 0)                                 ; stop recursion
          (t (+
              (if (funcall predicate n) n 0)          ; add n or 0 and
              (predicate-sum predicate (- n 1))))))   ; the recursed sum to (n - 1)

;; in the repl use
;; (predicate-sum 'multiple-of-3-or-5p 999)

Other than &quot;stuff&quot; relevant to the code above, I came across a few question while working on this problem.

What is the natural Lispy way to define upper boundaries? Include or exclude the specific value? Ie, if you see (summation 3 6) you think 3+4+5 or 3+4+5+6?
Is there a standard way to make a list of numbers 0 to 1000 (999)? Something like (make-list 0 1000)?

Thanks in advance
Conditions
In general something like &quot;if a then true else false&quot; can be simplified as &quot;a&quot;. So your first function could be simplified as:
(defun multiple-of-3-or-5p (n)
  &quot;predicate for multiple of 3 or 5&quot;
  (or (= 0 (rem n 3)) (= 0 (rem n 5))))

Cond with only two cases
A cond with only two cases is written preferibly as an if. For instance:
(defun sum35 (n)
  &quot;sum all multiples of 3 or 5 up to n (including n)&quot;
  (if (= n 0)
      0
      (+ (if (multiple-of-3-or-5p n) n 0) (sum35 (- n 1)))))

Use the operators 1+ and 1- instead of adding or subtracting 1
The usual way of writing (- n 1) is (1- n).
Recursion and Iteration
Common Lisp has a very powerful iteration construct, loop (see for instance here for a detailed
discussion), that can make
simpler to write cases like in the last two functions. For instance:
(defun sum35 (n)
  &quot;sum all multiples of 3 or 5 below n&quot;
  (loop for i below n
        when (multiple-of-3-or-5p i) sum i))

; (sum35 1000)

Analogously,
(defun predicate-sum35 (predicate n)
  &quot;sum integers up to n (including n) that match the predicate&quot;
  (loop for i below n
        when (funcall predicate i) sum i))

; (predicate-sum35 #'multiple-of-3-or-5p 1000)

(note the use of #' to get a function).
Finally, to answer your last two questions:

The “natural” way in Common Lisp is to exclude the last value, as in all predefined functions that specify a range (for instance to get a substring with the first two characters of &quot;foo&quot;, you can write (subseq &quot;foo&quot; 0 2), that returns &quot;fo&quot;,
with the index starting from 0).

A primitive function does not exists. You can obtain a list of this kind very easily by using loop, for instance: (loop for i below 1000 collect i).


Edited
As suggested in a comment by @slepic, the algorithm is not the best one, since it checks for all the numbers from 0 to n, while one could simply sum directly all the multiples. Here is a possible solution:
(defun sum35 (n)
  (flet ((sum-m (k)
           (loop for i from k below n by k sum i)))
    (+ (sum-m 3) (sum-m 5) (- (sum-m 15)))))

Or you can use a direct formula, like that in another comment.