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

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -