如何知道列表何时在 CLIPS 中排序
How to know when a list is ordered in CLIPS
我正在做一个 CLIPS 练习,我按降序排列列表。问题是我只想打印一次列表,而且只有在它被完全订购后,有人知道我该如何检查吗?到目前为止我有这个,它正确地排序了列表。提前致谢:)
(deffacts hechos-iniciales
(lista 5 7 3 1 8 4 2 6)
)
(defrule ordena-lista
?indice<-(lista $?ini ?num1 ?num2 $?fin)
(test (< ?num1 ?num2))
=>
(assert (lista $?ini ?num2 ?num1 $?fin))
(retract ?indice)
)
您可以创建较低的显着性规则来打印结果,或者让打印列表的规则检查是否没有未排序的列表。
CLIPS>
(deffacts hechos-iniciales
(lista 5 7 3 1 8 4 2 6))
CLIPS>
(defrule ordena-lista
?indice<-(lista $?ini ?num1 ?num2 $?fin)
(test (< ?num1 ?num2))
=>
(assert (lista $?ini ?num2 ?num1 $?fin))
(retract ?indice))
CLIPS>
(defrule print-lista-1
(declare (salience -10))
(lista $?values)
=>
(printout t "print1: " (str-implode ?values) crlf))
CLIPS>
(defrule print-lista-2
(lista $?values)
(not (lista $?ini ?num1 ?num2&:(< ?num1 ?num2) $?fin))
=>
(printout t "print2: " (str-implode ?values) crlf))
CLIPS> (reset)
CLIPS> (run)
print2: 8 7 6 5 4 3 2 1
print1: 8 7 6 5 4 3 2 1
CLIPS>
我正在做一个 CLIPS 练习,我按降序排列列表。问题是我只想打印一次列表,而且只有在它被完全订购后,有人知道我该如何检查吗?到目前为止我有这个,它正确地排序了列表。提前致谢:)
(deffacts hechos-iniciales
(lista 5 7 3 1 8 4 2 6)
)
(defrule ordena-lista
?indice<-(lista $?ini ?num1 ?num2 $?fin)
(test (< ?num1 ?num2))
=>
(assert (lista $?ini ?num2 ?num1 $?fin))
(retract ?indice)
)
您可以创建较低的显着性规则来打印结果,或者让打印列表的规则检查是否没有未排序的列表。
CLIPS>
(deffacts hechos-iniciales
(lista 5 7 3 1 8 4 2 6))
CLIPS>
(defrule ordena-lista
?indice<-(lista $?ini ?num1 ?num2 $?fin)
(test (< ?num1 ?num2))
=>
(assert (lista $?ini ?num2 ?num1 $?fin))
(retract ?indice))
CLIPS>
(defrule print-lista-1
(declare (salience -10))
(lista $?values)
=>
(printout t "print1: " (str-implode ?values) crlf))
CLIPS>
(defrule print-lista-2
(lista $?values)
(not (lista $?ini ?num1 ?num2&:(< ?num1 ?num2) $?fin))
=>
(printout t "print2: " (str-implode ?values) crlf))
CLIPS> (reset)
CLIPS> (run)
print2: 8 7 6 5 4 3 2 1
print1: 8 7 6 5 4 3 2 1
CLIPS>