In Jess, how would I add a slot to a template through a rule? -


as example, have:

(deftemplate animal (slot has-feathers (default false)) (slot name (default "george")) ) 

and in rule have:

(defrule bird-test ?a <-(animal (has-feathers ?)) => (printout t ?a.name " bird" crlf) "add slot 'bird' ?a or animal" ) 

how this? , thank in advance

edit: guys! think understand need do.

in addition ernest's proposal of providing slot front, might consider multislot can act container sorts of properties rules might detect animal.

(deftemplate animal     (slot name)     (slot has-feathers)     (multislot props)...) 

you can write the

(defrule bird-test   (declare (no-loop true))   ?a <-(animal (has-feathers true)(props $?ex )) =>   (modify ?a (props $?ex isbird))   (printout t ?a.name "'s props: " ?a.props crlf) ) 

alternatively, general kind of deftemplate can used express kinds or properties dynamically:

(deftemplate is-a     (slot thing)     (slot property)) 

but goes beyond mere answer.


Popular posts from this blog

javascript - Js, document.getElementById("ID").innerHTML, error -

objective c - Is there a way in OCMockito to make stubs fail when an unknown method is called? -

jquery - jqGrid update specific column data with out refreshing the entire column? -