CLIPS:计算不同的产品
CLIPS: counting different products
我有一些列表形式的事实:(list day1 apple milk bread) (list day 2 bread milk) 我想计算这些事实中每一天的不同产品。我怎样才能计算它们?
我想要的结果是 (list day1 3) (list day2 2)
CLIPS (6.4 2/9/21)
CLIPS>
(defrule list-count
(list ?day $?items)
=>
(assert (count ?day (length$ ?items))))
CLIPS>
(assert (list day1 apple milk bread)
(list day2 bread milk))
<Fact-2>
CLIPS> (agenda)
0 list-count: f-2
0 list-count: f-1
For a total of 2 activations.
CLIPS> (run)
CLIPS> (facts)
f-1 (list day1 apple milk bread)
f-2 (list day2 bread milk)
f-3 (count day2 2)
f-4 (count day1 3)
For a total of 4 facts.
CLIPS>
我有一些列表形式的事实:(list day1 apple milk bread) (list day 2 bread milk) 我想计算这些事实中每一天的不同产品。我怎样才能计算它们? 我想要的结果是 (list day1 3) (list day2 2)
CLIPS (6.4 2/9/21)
CLIPS>
(defrule list-count
(list ?day $?items)
=>
(assert (count ?day (length$ ?items))))
CLIPS>
(assert (list day1 apple milk bread)
(list day2 bread milk))
<Fact-2>
CLIPS> (agenda)
0 list-count: f-2
0 list-count: f-1
For a total of 2 activations.
CLIPS> (run)
CLIPS> (facts)
f-1 (list day1 apple milk bread)
f-2 (list day2 bread milk)
f-3 (count day2 2)
f-4 (count day1 3)
For a total of 4 facts.
CLIPS>