-1

I am currently writing a program that will simulate the propositional laws. I have received a function my-test to determine whether certain characters are in a string and i works fine if i pass only a single slot variable but it won#t accept a multislot/multi value variable.

I have go the code working i f a pass for example ?sigle but if I try and pass $?symbol to the program it says that it is epecting a string or symbol.

(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))))

(deffunction my-test ($?symbol) (not (or (str-index "^" ?symbol) (str-index "v" ?symbol)))) 

(defrule negative
(sentence (sent $?before "~" "(" "~" $?symbol ")" $?after))
(test (my-test $?symbol))
 =>
 (assert (sentence (sent $?before $?symbol $?after))))

(run)
Please enter a sentence: Use ~ for not and => for implies, or(v) and and(^) please. For predicates use { and } Example exists{richard}
~(~P v Q)
[ARGACCES2] Function 'str-index' expected argument #2 to be of type symbol, string, or instance name.
[PRCCODE4] Execution halted during the actions of deffunction 'my-test'.

This is the error i receive when i run the program i have a feeling that i need to do a conversio but am not quite sure what exctly needs to be done. Thx for the help

1 Answers1

0

If you're passing multiple symbols to the my-test function to test, you need to iterate over them using the foreach function.

         CLIPS (6.31 4/1/19)
CLIPS> (deftemplate sentence (multislot sent))
CLIPS> 
(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))))
CLIPS> 
(deffunction my-test (?symbols)
   (foreach ?s ?symbols 
      (if (or (str-index "^" ?s) (str-index "v" ?s))
         then (return FALSE)))
   (return TRUE)) 
CLIPS> 
(defrule negative
   (sentence (sent $?before "~" "(" "~" $?symbol ")" $?after))
   (test (my-test $?symbol))
    =>
    (assert (sentence (sent $?before $?symbol $?after))))
CLIPS> (run)
Please enter a sentence: Use ~ for not and => for implies, or(v) and and(^) please. For predicates use { and } Example exists{richard}
~(~P v Q)
CLIPS>
Gary Riley
  • 10,130
  • 2
  • 19
  • 34