您可以使用 max 函数查找其参数的最大值。您可以在规则条件下将数字列表绑定到多字段变量。但是 max 函数需要单独的参数,因此您不能仅将其传递为多字段值。您可以使用 expand $ 函数将多字段值拆分为用于函数调用的单独参数。 max 函数在CLIPS 6.3中期望至少2个参数,在CLIPS 6.4中期望至少1个参数,因此,为了完整起见,您需要处理这些情况。您可以创建一个deffunction来处理代码中的这些极端情况。
CLIPS (6.31 6/12/19)
CLIPS>
(deffunction my-max ($?values)
(switch (length$ ?values)
(case 0 then (return))
(case 1 then (return (nth$ 1 ?values)))
(default (return (max (expand$ ?values))))))
CLIPS>
(deffacts list
(list 1 2 3 4 5 6 7 6 5 4 3 2 1))
CLIPS>
(defrule list-max
(list $?values)
=>
(printout t "list max = " (my-max ?values) crlf))
CLIPS>
(deftemplate patient
(slot name)
(slot age)
(multislot tens_max)
(multislot tens_min))
CLIPS>
(deffacts data_patient
(patient (name John) (age 22) (tens_max 13 15 22 11) (tens_min 6 7 14 6)))
CLIPS>
(defrule patient-max
(patient (tens_min $?values))
=>
(printout t "patient max = " (my-max ?values) crlf))
CLIPS> (reset)
CLIPS> (run)
patient max = 14
list max = 7
CLIPS>
本文链接:https://www.f2er.com/3108972.html