Fast Prime Number Generation in Clojure

Here’s another approach that celebrates Clojure’s Java interop. This takes 374ms on a 2.4 Ghz Core 2 Duo (running single-threaded). I let the efficient Miller-Rabin implementation in Java’s BigInteger#isProbablePrime deal with the primality check. (def certainty 5) (defn prime? [n] (.isProbablePrime (BigInteger/valueOf n) certainty)) (concat [2] (take 10001 (filter prime? (take-nth 2 (range 1 Integer/MAX_VALUE))))) … Read more

LET versus LET* in Common Lisp

LET itself is not a real primitive in a Functional Programming Language, since it can replaced with LAMBDA. Like this: (let ((a1 b1) (a2 b2) … (an bn)) (some-code a1 a2 … an)) is similar to ((lambda (a1 a2 … an) (some-code a1 a2 … an)) b1 b2 … bn) But (let* ((a1 b1) (a2 … Read more

values function in Common Lisp

Multiple Values in CL The language Common lisp is described in the ANSI standard INCITS 226-1994 (R2004) and has many implementations. Each can implement multiple values as it sees fit, and they are allowed, of course, to cons up a list for them (in fact, the Emacs Lisp compatibility layer for CL does just that … Read more