如何列出LISP中从1800开始的所有the年?

时间:2019-04-16 16:38:12

标签: lisp common-lisp clisp

我下面的代码带一个参数,并以相反的顺序打印所有的all年列表。我如何才能将1800作为默认输入并仅运行命令(跳跃)以列出1800-2018年的所有the年?

代码:

(defun leap (q)

    (if (< q 1800)
        (RETURN-FROM leap nil)
    )

    (leap (- q 1))

    (if (leapyear q)
        (push q mylist)
    )
    mylist
)


(reverse(leap 2018))

1 个答案:

答案 0 :(得分:2)

我无法完全理解您要做什么,但是:

(defun leapyearp (y)
  ;; is Y a leap year, as best we can tell?
  (= (nth-value 3 (decode-universal-time
                   (+ (encode-universal-time 0 0 0 28 2 y)
                      (* 60 60 24))))
     29))

(defun leapyears (&key (start 1800) (end (nth-value 5 (get-decoded-time))))
  ;; all the leap years in a range
  (loop for y from start to end
        if (leapyearp y) collect y))