如何获取应用于方程的用户输入(以数字的形式)



我试图编程一个场景,用户将输入两条信息,在基线(6MWDbaseline) 6分钟步行距离米,然后在24周(6MWD24weeks) 6分钟步行距离米。我希望用户提供这些信息,而不是我在程序中断言它们。输入这些数字后,需要将它们应用于方程式:(6mwd24周- 6MWDbaseline) = x然后是这个方程:x/6MWDbaseline = y其中,如果y>/= 0.2,则程序将表示成功。如果y在0.05-0.19之间,则该程序表示临床改善。如果y为<0.049,则程序将表示失败。

在我的脚本测试早期,在我甚至可以尝试编程我的"临床改善"或"失败"行之前,我的6MWDbaseline和6MWD24weeks的用户输入预计将是整数或浮点数。你能告诉我哪里做错了吗?

CLIPS> (clear)
CLIPS> (defrule MAIN::6WMDbaseline-check
=>
(printout t "What is the distance on the baseline 6-minute walk distance in meters?" crlf)
(assert (6MWDbaseline (read))))
CLIPS> (defrule MAIN::6MWD24week-check
=>
(printout t "What is the distance on the 24-week 6-minute walk distance in meters?" crlf)
(assert (6MWD24week (read))))
CLIPS> (defrule MAIN::success-decision
(6MWDbaseline ?6MWDbaseline)
(6MWD24week ?6MWD24week)
=>
(if (- 6MWD24week 6MWDbaseline = x) and (/ x 6MWDbaseline >0.2))
then
(printout t "Primary outcome met, greater than 20% improvement in 6-minute walk distance" crlf))
[ARGACCES2] Function '-' expected argument #1 to be of type integer or float.
ERROR:
(defrule MAIN::success-decision
(6MWDbaseline ? 6MWDbaseline)
(6MWD24week ? 6MWD24week)
=>
(if (- 6MWD24week 6MWDbaseline = x)
CLIPS> 

提前感谢您的帮助!玛尼

使用绑定函数将值赋给规则操作中的变量。此外,变量名必须以字母开头。

CLIPS (6.4 2/9/21)
CLIPS> 
(defrule 6WMDbaseline-check
=>
(printout t "What is the distance on the baseline 6-minute walk distance in meters?" crlf)
(assert (6MWDbaseline (read))))
CLIPS> 
(defrule 6MWD24week-check
=>
(printout t "What is the distance on the 24-week 6-minute walk distance in meters?" crlf)
(assert (6MWD24week (read))))
CLIPS> 
(defrule success-decision
(6MWDbaseline ?baseline)
(6MWD24week ?week24)
=>
(bind ?x (- ?week24 ?baseline))
(bind ?y (/ ?x ?baseline))
(switch TRUE
(case (> ?y 0.2)
then
(printout t "Primary outcome met, greater than 20% improvement in 6-minute walk distance" crlf))
(case (and (>= ?y 0.05) (<= ?y 0.2))
then
(printout t "Primary outcome improved, between 5% and 20% improvement in 6-minute walk distance" crlf))
(case (< ?y 0.05)
then
(printout t "Primary outcome failed, less than 5% improvement in 6-minute walk distance" crlf))))
CLIPS> (reset)
CLIPS> (run)
What is the distance on the baseline 6-minute walk distance in meters?
100
What is the distance on the 24-week 6-minute walk distance in meters?
121
Primary outcome met, greater than 20% improvement in 6-minute walk distance
CLIPS> (reset)
CLIPS> (run)
What is the distance on the baseline 6-minute walk distance in meters?
100
What is the distance on the 24-week 6-minute walk distance in meters?
115
Primary outcome improved, between 5% and 20% improvement in 6-minute walk distance
CLIPS> (reset)
CLIPS> (run)
What is the distance on the baseline 6-minute walk distance in meters?
100
What is the distance on the 24-week 6-minute walk distance in meters?
104
Primary outcome failed, less than 5% improvement in 6-minute walk distance
CLIPS> 

最新更新