0

I am trying to print my 1234 list like:

1
12
123
1234

Here is my code:

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

I'm not sure exactly how I should continue...

4

1 回答 1

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> 
于 2014-03-10T18:32:07.997 回答