1)如果用户输入的不是yes/no,我需要一种方法来重复这个问题。
2)我需要一种允许剪辑接受小写和大写字母的方法。
我通过谷歌搜索找到了这个样本,但我不太确定它在某些行上是如何工作的。有人能给我解释一下这是怎么工作的吗?或者有一个更好的方法来做我需要的两件事。
(deffunction ask-question (?question $?allowed-values)
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer)))
(while (not (member ?answer ?allowed-values)) do
(printout t ?question)
(bind ?answer (read))
(if (lexemep ?answer)
then (bind ?answer (lowcase ?answer))))
?answer)
(deffunction yes-or-no-p (?question)
(bind ?response (ask-question ?question yes no y n))
(if (or (eq ?response yes) (eq ?response y))
then yes
else no))发布于 2017-09-19 06:16:55
ask-question函数的伪代码:
Print the question.
Get the answer.
If
The answer is a symbol or string
Then
Convert the answer to lower case.
End if
While the answer is not one of the allowed values
Print the question.
Get the answer.
If
The answer is a symbol or string
Then
Convert the answer to lower case.
End if
End while
Return the answer.https://stackoverflow.com/questions/46285344
复制相似问题