Hi Alan,
The CLIPS language can't express this idea directly, but instead, you
can use procedural programming and the Reflection API to do what you
want. This is a (untested, but hopefully pretty close) function to
return a multifield containing the names of the slots in a deftemplate:
(deffunction list-slots (?dt-name)
;; Get the ValueVector representation of the deftemplate
(bind ?dt (call (call (engine) findDeftemplate ?dt-name) deftemplateData))
;; counter for loop below, aimed at first slot name
(bind ?i (+ (get-member jess.RU FIRST_SLOT) (get-member jess.RU DT_SLOT_NAME)))
;; length of the ValueVector
(bind ?size (call ?dt size))
(bind ?retval (create$))
(while (< ?i ?size)
;; fetch this slot name, append to list
(bind ?retval (create$ ?retval (call ?dt get ?i)))
;; increment the counter by the size of a slot
(bind ?i (+ ?i (get-member jess.RU DT_SLOT_SIZE))))
(return ?retval))
Of course, you could also write a Userfunction in Java to do the same
thing, which could be more efficient.
I think Alan Barton wrote:
>
>
> Any help on the following problem would be appreciated:
>
> If I define a template to be:
> ( deftemplate templateName
> ( slot One )
> ( slot Two )
> )
>
> How can I get information about the slots from a rule?
>
> e.g. The following do not work, but are my attempts at
> describing the desired behavour...
>
> Attempt 1:
> Match the contents of the template and print the list to stdout...
> (defrule ruleName1
> ( templateName $?contents)
> =>
> (printout t ?contents)
> )
>
> Attempt 2:
> Get the factId from any asserted fact that is related to templateName
> and somehow use the factId to get access to the slot named Two...
> (defrule ruleName2
> ?factId <- ( templateName )
> =>
> (printout t ?factId.Two )
> )
>
> Cheers,
> Alan.
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (510) 294-2154
Sandia National Labs FAX: (510) 294-2234
Org. 8920, MS 9214 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------