首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何获得应用于方程的用户输入(作为一个数字)

如何获得应用于方程的用户输入(作为一个数字)
EN

Stack Overflow用户
提问于 2022-11-30 07:09:13
回答 1查看 18关注 0票数 1

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

我在脚本测试的早期就遇到了一个错误,甚至在我试图对我的“临床改进”或“失败”行进行编程之前,我的用户输入的6 MWD基线和6MWD24周预期是整数或浮动。对我可能做错了什么有什么指导吗?

代码语言:javascript
复制
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> 

谢谢您的帮助!玛妮

EN

回答 1

Stack Overflow用户

发布于 2022-11-30 18:11:04

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

代码语言:javascript
复制
         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> 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74624002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档