1

I am trying to program a scenario where a user will input two pieces of information, a 6-minute walk distance in meters at baseline (6MWDbaseline) and then a 6-minute walk distance in meters at 24-weeks (6MWD24weeks). I want the user to supply those pieces of information rather than me asserting them within the program. Once those numbers are entered they need to be applied to the equation: (6MWD24weeks - 6MWDbaseline) = x and then to this equation: x / 6MWDbaseline = y Where, if y >/= 0.2 then the program will denote success. If y is between 0.05-0.19 then the program will denote clinical improvement. If y is <0.049 then the program will denote failure.

I get an error early on in my script testing, before I can even try to program my 'clinical improvement' or 'failure' lines, that my user inputs of 6MWDbaseline and 6MWD24weeks are expected to be integers or floats. Any guidance on what I might be doing wrong?

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> 

Thanks in advance for any assistance! Marnie

1 Answers1

1

Use the bind function to assign values to variables in the actions of a rule. In addition, variable names must begin with a letter.

         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> 
Gary Riley
  • 10,130
  • 2
  • 19
  • 34