Frisco wrote:I'm (attempting to) teach myself from the book "ANSI Common LISP", by Paul Graham.
Unfortunately, Paul Graham doesn't really like Common Lisp as it is. Which is why he created his own language,
Arc. Personally I prefer Common Lisp, even though it is far from perfect. There are
some notes here which points out how Grahams style differs from more typical CL style.
Frisco wrote:Wasn't thinking at all when deciding to use camelCase. Taught to do in C++ and it just kind of came naturally.
I suppose it beats using underscores as separators, but thankfully Lisp doesn't have a problem with dashes in identifiers (and many more characters which are usually invalid). One advantage here is that it allows much nicer symbol completion than in many other dynamic languages, since dashes act as unambiguous component separator, so CL supporting editor (usually Emacs) can easily expand for example m-v-b to multiple-value-bind, which makes using those long operators much less cumbersome.
Frisco wrote:This was written with the intention of brute-forcing from 1 to the number, checking all of them for primality. "Ans" would store the biggest one and return it at the end.
But the problem is I don't see where you check that the number is not only prime, but a factor of your input number. As it is, as far as I can tell, it find a biggest prime smaller or equal than the number, which is very much not the same thing. One way to approach it is to find the smallest factor, which must be a prime for obvious reasons, and then repeat on a reduced number until it is boiled down to one. This avoids separate primality testing, although it is obviously not really efficient. I guess the other way would be to generate all primes up to half a number using Eratosthenes sieve and check them one by one from the top. That is fairly trivial. As long as your numbers are smaller than
array-dimension-limit, but at that point it would consume too much time anyway.
Frisco wrote:until I've seen how loop and iterate work.
Note that those are quite similar. One main difference are that LOOP is built in, and iterate is not. It is a really nice example how CL can be extended with macros, since it is just a library. Currently the best and pretty good way to install libraries is
quicklisp. The reason why I personally prefer iterate is that is uses symbolic expressions (ie. parentheses) more, which makes it much easier to manipulate with Emacs+
paredit s-exp handling operations.