我有下面这段代码,它接受一个参数并以相反的顺序打印所有闰年列表。我怎样才能让它以 1800 作为默认输入并运行命令 (leap) 来列出 1800-2018 的所有闰年?
代码:
(defun leap (q)
(if (< q 1800)
(RETURN-FROM leap nil)
)
(leap (- q 1))
(if (leapyear q)
(push q mylist)
)
mylist
)
(reverse(leap 2018))
最佳答案
我不能完全理解你想做什么,但是:
(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))
关于lisp - 如何在 LISP 中列出从 1800 开始的所有闰年?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55712925/