【问题标题】:CLIPS: How to evaluate multifield values as integersCLIPS:如何将多字段值评估为整数
【发布时间】:2016-01-27 02:04:05
【问题描述】:

我正在努力正确评估多字段值的整数值。

我最终需要的是对仅包含整数的多槽进行模式匹配,并能够判断“列表”是否按升序排列。

到目前为止我所拥有的:

(defclass status 
    (is-a USER)
    (role concrete)
    (pattern-match reactive)
    (multislot numbers
        (create-accessor write)
        (type INTEGER) 
        (range 1 ?VARIABLE) 
        (default 1)
     )
)

(defrule asc
    ?st <- (object (is-a status) (numbers $?n))
    (test (> (length ?n) 2))
    (test (< (first$ ?n) (rest$ ?n)))
=> 
    (printout t "List " ?n " is ascending" crlf)
)

(make-instance of status (numbers 1 2 3))

我知道这可能不是扩展多槽并为 (

(first$ ?n)

不计算为整数。

我的问题是: 如何获取值列表的值并将其“解析”为整数? 其次,如何扩展这些值以使它们成为 (

【问题讨论】:

    标签: clips expert-system


    【解决方案1】:

    使用 nth$ 函数从多字段中检索单个值。对于第一个值,您将使用 (nth$ 1 ?n)。但是,在您的规则中,您需要做的就是使用 expand$ 函数将数字槽的值拼接到

    CLIPS> 
    (defclass status 
       (is-a USER)
       (multislot numbers))
    CLIPS> 
    (defrule asc
       (object (is-a status) (numbers $?n))
       (test (> (length ?n) 1))
       (test (< (expand$ ?n)))
       => 
       (printout t "List " ?n " is ascending" crlf))
    CLIPS> (make-instance of status (numbers 1 2 3))
    [gen1]
    CLIPS> (make-instance of status (numbers 2 3 1 4))
    [gen2]
    CLIPS> (run)
    List (1 2 3) is ascending
    CLIPS>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-22
      相关资源
      最近更新 更多