2017-12-03 8 views
0

Jessで複数のユーザー入力を読み込んでいます。ルールは:条件付きのJessでのルール実行の終了

(defrule specify-input 
    ?act <- (Actuator (name 0) (inputVoltage ?v1&0)) 
    => 
    (printout t "Please specify input voltage of the actuator. [V] " crlf) 
    (modify ?act (inputVoltage (read))) 
    (printout t "Please specify desired force of the actuator. [N] " crlf) 
    (modify ?act (Force (read))) 
    (printout t "Please specify desired stroke lenght of the actuator. [mm] " crlf) 
    (modify ?act (StrokeLength (read)))) 

Iは、入力電圧の値をチェックできるようにしたいと思い、それが定義された範囲外の場合、0に設定し、さらにルールの実行を終了します。それを行う方法はありますか?

答えて

1

if関数を使用することができます(cf. Jessマニュアル第3.8.2節参照)。

(printout t "Please specify input voltage of the actuator. [V] " crlf) 
(bind ?v (read)) 
(if (and (> ?v 0) (<= ?v 1000)) then 
    (printout t "Please specify desired force of the actuator. [N] " crlf) 
    (bind ?f (read)) 
    (printout t "Please specify desired stroke lenght of the actuator. [mm] " crlf) 
    (bind ?sl (read)) 
    (modify ?act (inputVoltage ?iv)(Force ?f)(StrokeLength ?sl)) 
) else (
    (printout t "invalid voltage" crlf) 
) 

他の値についても同様のチェックが行われる場合があります。

しかし、ユーザーに別のチャンスが与えられるべきではありませんか? Cf。セクション3.8.1。

(while true do 
    (printout t "Please specify input voltage of the actuator. [V] " crlf) 
    (bind ?v (read)) 
    (if (and (> ?v 0) (<= ?v 1000)) then (break)) 
    (printout t "invalid voltage, not in (0,1000]" crlf) 
) 
関連する問題