首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在剪辑中断言字符串

在剪辑中断言字符串
EN

Stack Overflow用户
提问于 2020-07-27 04:18:46
回答 1查看 143关注 0票数 0

我试图将name的值断言到变量中,但是当我断言它时,这个值是以引号形式出现的,并且在末尾还有一个额外的空间。

代码语言:javascript
复制
   (defrule discount_amt_group 
    (exists (Student (age 14)(marks ?q&:(> ?q 40))))
    =>
    (bind ?name "")
    (do-for-all-facts ((?p Student))
                  (or (eq ?p:marks 80)
                     (eq ?p:marks 75)
                     (eq ?p:marks 90))
    (bind ?name (str-cat ?name ?p:name " "))
    (bind ?totalMarks (+ ?totalMarks ?p:marks)))
    (assert (StudOut(names ?name)))

期望值将是(名为哈利·罗恩·金格),但现在它将以“哈利·罗恩·金格”的名字出现,请提出建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-27 17:14:49

将名称表示为多字段值,而不是字符串。您可以使用create$函数最初创建一个空的多字段值,然后再向其追加值。

代码语言:javascript
复制
         CLIPS (6.31 6/12/19)
CLIPS> 
(deftemplate Student
   (slot name)
   (slot age)
   (slot marks))
CLIPS>    
(deftemplate StudOut
   (multislot names)
   (slot totalMarks))
CLIPS>    
(deffacts Students
   (Student (name Harry) (age 14) (marks 80))
   (Student (name Ron) (age 15) (marks 75))
   (Student (name Ginger) (age 14) (marks 90))
   (Student (name Sally) (age 12) (marks 95)))
CLIPS>    
(defrule discount_amt_group 
   (exists (Student (age 14)(marks ?q&:(> ?q 40))))
   =>
   (bind ?name (create$))
   (bind ?totalMarks 0)
   (do-for-all-facts ((?p Student))
                     (or (eq ?p:marks 80)
                         (eq ?p:marks 75)
                         (eq ?p:marks 90))
      (bind ?name (create$ ?name ?p:name))
      (bind ?totalMarks (+ ?totalMarks ?p:marks)))
   (assert (StudOut (names ?name)
                    (totalMarks ?totalMarks))))
CLIPS> (reset)
CLIPS> (run)
CLIPS> (facts)
f-0     (initial-fact)
f-1     (Student (name Harry) (age 14) (marks 80))
f-2     (Student (name Ron) (age 15) (marks 75))
f-3     (Student (name Ginger) (age 14) (marks 90))
f-4     (Student (name Sally) (age 12) (marks 95))
f-5     (StudOut (names Harry Ron Ginger) (totalMarks 245))
For a total of 6 facts.
CLIPS> 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63108658

复制
相关文章

相似问题

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