您好,我正在编写一个模拟命题定律的程序。我想确保某些字符不包含在我的变量中。有一个简单的功能可以做到这一点。
如果我的变量只是一个字符,但我想使其与多插槽变量一起使用,我现在可以使用它。
(deftemplate sentence (multislot sent))
(defrule read-from-user
=>
(bind ?response "")
(printout t "Please enter a sentence: Use ~ for not and => for implies, or(v) and and(^) please. For predicates use { and } Example exists{richard}" crlf)
(bind ?response (explode$ (readline)))
(bind ?response (replace-member$ ?response "(" (sym-cat "(")))
(bind ?response (replace-member$ ?response ")" (sym-cat ")")))
(bind ?response (replace-member$ ?response "~" (sym-cat "~")))
(bind ?response (replace-member$ ?response "v" (sym-cat "v")))
(bind ?response (replace-member$ ?response "=>" (sym-cat "=>")))
(bind ?response (replace-member$ ?response "^" (sym-cat "^")))
(bind ?response (replace-member$ ?response "[" (sym-cat "[")))
(bind ?response (replace-member$ ?response "]" (sym-cat "]")))
(bind ?response (replace-member$ ?response "{" (sym-cat "{")))
(bind ?response (replace-member$ ?response "}" (sym-cat "}")))
(assert (sentence (sent ?response))))
(defrule negative
(sentence (sent $?before "~" "(" "~" ?symbol ")" $?after))
(test (neq ?symbol "~" "(" ")" "=" "^" "v"))
=>
(assert (sentence (sent $?before $?symbol $?after))))
这段代码适用于单个字符,但我知道该怎么做 将?符号转换为$符号,并仍然检查是否没有字符(,),〜,=等在$符号中。
那么,如果有任何类似的功能可以在C#中进行比较,我可以使用她吗?谢谢你们
答案 0 :(得分:0)
使用str-index函数确定字符串中是否包含字符序列:
CLIPS (6.31 4/4/19)
CLIPS> (str-index "^" "abc")
FALSE
CLIPS> (str-index "^" "ab^c")
3
CLIPS>