CLIPS中的列表操作(专家系统)

时间:2016-01-16 22:58:44

标签: clips

我只想要一个函数来打印每行的项目。 我在尝试:

(deffunction myprint (?first $?rest)
(if (neq ?rest nil) then
    (printout t ?first crlf)
    (myprint ?rest)))

有什么问题?

1 个答案:

答案 0 :(得分:1)

使用length函数确定列表是否为空(返回值为0)。将列表与符号nil进行比较将始终失败。

你想打印?首先即使?休息是空的。否则,永远不会打印最后一个元素。

没有必要使用递归。

CLIPS> 
(deffunction myprint ($?rest)
   (foreach ?r $?rest
      (printout t ?r crlf)))
CLIPS> (myprint a b c)
a
b
c
CLIPS> (myprint (create$ a b) (create$ c d))
a
b
c
d
CLIPS>
相关问题