Page 1 of 1

### Brief codereview and freshman pep talk

Posted: Thu Jan 17, 2019 4:10 am
Hi everyone! Not exactly a homework again, but fits here better.

I'm a C++ programmer and on my staycation I've decided to challenge myself and do a couple of Project Euler problems and to challenge myself even more I've decided that it is the perfect time for me to realize my long-held dream and learn some lisp at last! I've read several chapters of Land of Lisp, that's all my background here. So my first question is where I can discuss things I wrote preferable in realtime (e.g. IRC or telegram), is this forum alive anyway?

The problem itself (it is deep in an archive so now we can discuss it freely without spoilers):
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.
After a considerable amount of time I've came up with something like that

Code: Select all

``````(defun sum-multiplies-by-3-or-5 (n)
(labels ((is-dividable-by (num divisor)
(zerop (mod num divisor)))
(is-dividable-by-3-or-5 (num)
(or (is-dividable-by num 3)
(is-dividable-by num 5)))
(impl (cur sum)
(cond ((= cur n) sum)
((is-dividable-by-3-or-5 cur) (impl (1+ cur) (+ sum cur)))
((impl (1+ cur) sum)))))
(impl 3 0)))``````
So now I have a billion questions about how good this code is, e.g
* should I hide functions like is-dividable-by or make them global if they are generic enough?
* recursion is a more true way of doing that than a loop?
* is the pattern of doing a local function to use it recursively good?
* what is not so good in this code that you can see right away?

Thanks!

### Re: Brief codereview and freshman pep talk

Posted: Sun Jan 20, 2019 1:44 pm
where I can discuss things I wrote preferable in realtime (e.g. IRC or telegram)
looks like I found a pretty cool Discord channel tho