I think that portalguy wrote:
>> After few attempts in jess script i gave up
>> Is there away on the RHS of the rule to guery the facts by the
>> fact template type, slot name and slot value?

Awww... I was having fun with this one!
Anyway, here's my hack... (what do you think, Ernest?  Is there ever going
to be the Jess equivalent of an Obfuscated Perl code contest? - JM)

;;============ d.clp ============
(clear)
(watch all)

(deftemplate foo
  (slot name)
  (slot bar)
  (slot data))

(deffunction getFactsByTemplate-Slot-Value (?t ?s ?v)
"This is a weird way of using Jess"
  ;  Make the defquery string
  (bind ?fact nil)
  (bind ?query-name "getfactIdByTemplateAndSlotValue")
  (bind ?query (str-cat "(defquery " ?query-name " (declare (variables ?t ?s
?v)) (" ?t " (" ?s " " ?v ")))" ))
  (build ?query)
  (bind ?itt (run-query ?query-name ?t ?s ?v))
  (while (?itt hasNext)
    (bind ?token (call ?itt next))
    (bind ?fact (call ?token fact 1)))

  ;  Return the result
  (return ?fact)
)

(reset)
(assert (foo (bar 1)))
(printout t "The fact-ref =" (getFactsByTemplate-Slot-Value "foo" "bar" "1")
crlf)
;;================================

Jess> (batch d.clp)
 ==> Focus MAIN
 ==> f-0 (MAIN::initial-fact)
 ==> f-1 (MAIN::foo (name nil) (bar 1) (data nil))
MAIN::getfactIdByTemplateAndSlotValue: +1+1+1+1+2+t
 ==> f-2 (MAIN::__query-trigger-getfactIdByTemplateAndSlotValue "foo" "bar"
"1")
 <== f-2 (MAIN::__query-trigger-getfactIdByTemplateAndSlotValue "foo" "bar"
"1")
The fact-ref =<External-Address:jess.Fact>
Jess>

------------------------

Jason Morris
Morris Technical Solutions
[EMAIL PROTECTED]
www.morristechnicalsolutions.com
fax/phone: 503.692.1088

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to