fork download
  1. (defun prime? (n)
  2. (loop for i from 2 to (/ n 2) do
  3. (when (= (mod n i) 0)
  4. (return-from prime? NIL)))
  5. T)
  6.  
  7. (defun take-n-primes (n)
  8. (labels ((next-prime (current)
  9. (loop for i from (1+ current) do
  10. (when (prime? i)
  11. (return i)))))
  12. (let ((primes nil)
  13. (current-prime 2))
  14. (dotimes (i n)
  15. (push current-prime primes)
  16. (setf current-prime (next-prime current-prime)))
  17. (nreverse primes))))
  18.  
  19. (print (take-n-primes 10))
Success #stdin #stdout 0.02s 10600KB
stdin
Standard input is empty
stdout
(2 3 5 7 11 13 17 19 23 29)