【发布时间】:2020-02-09 13:52:39
【问题描述】:
我一直在研究这个问题,“做一个给定两个月的函数,说如果第一个月出现在日历打印中的第二个月之前是真的”。我只能使用 , cons, append, list, equal, defun, car, cdr, cond , T , NIL
尽管最好的方法是为每个月份分配一个值,并制作单独的函数,一个函数用于月份,另一个函数用于验证月份。
这是我的代码:我不会粘贴所有代码,因为我仍在测试: 我是这样做的,不确定我是否为月份分配了正确的值,导致我不确定如何为字符串赋值。
(defun months(month)
(cond ((null month)0)
((= month (format t "january") 1))
((= month (format t "february") 2))
nil ))
the other function:
(defun check-month(month1 month2)
(if (< (months month1) (months month2))
T
NIL
)
)
and when I called the function check-month it says:
(check-month "january" "february")
*** - IF: variable months has no value
The actual result should be like this:
(check-month “january” ”february”)
T
【问题讨论】:
-
问题陈述中没有对字符串的引用,你确定你没有让这变得比必要的更困难吗?
-
您的代码出现了一堆基本错误。这本书可能有助于学习 Lisp 的基础知识:cs.cmu.edu/~dst/LispBook 你可以从那里下载 PDF。
标签: lisp common-lisp