小编bin*_*yjc的帖子

在Common Lisp中打印前N个素数

我正在制作一个Common Lisp函数来打印前N个素数.到目前为止,我已设法编写此代码:

;globals 
(setf isprime 1) ;if 1 then its a prime, 0 if not.
(setf from 1)    ;start from 1
(setf count 0)   ;should act as counter to check if we have already 
                 ;    N primes printed

;function so far.
(defun prime-numbers (to)
  (if (> count to) nil(progn
      (is-prime from from)
      (if (= isprime 1) (print from)(setf count (+ count 1)))
      (setf isprime 1)
      (setf from (+ from 1))
      (prime-numbers to)))
  (if (>= count to)(setf count 0) (setf from …
Run Code Online (Sandbox Code Playgroud)

lisp printing primes clisp numbers

0
推荐指数
1
解决办法
5568
查看次数

标签 统计

clisp ×1

lisp ×1

numbers ×1

primes ×1

printing ×1