剪辑 - 在金字塔中打印数字列表

时间:2014-03-09 18:29:37

标签: clips

我正在尝试打印我的1234列表:

1
12
123
1234

这是我的代码:

    (deffacts lists 
            (list 1 2 3 4)
    )
    (defrule print
        (list $?x ? $?)
        =>
        (printout t ?x )
    )

我不确定我应该如何继续...

1 个答案:

答案 0 :(得分:0)

CLIPS> 
(deffacts lists 
   (list 1 2 3 4))
CLIPS> 
(deffunction pyramid-print (?list)
   (loop-for-count (?i (length$ ?list))
      (printout t (implode$ (subseq$ ?list 1 ?i)) crlf)))
CLIPS>        
(defrule print
   (list $?x)
   =>
   (pyramid-print ?x))
CLIPS> (reset)
CLIPS> (run)
1
1 2
1 2 3
1 2 3 4
CLIPS>