KW issue: doing hash-table queries from TEST predicates
Greetings. I'd like clarification on a KW issue we're having. The doc says:
"Lisp tests, and any functions invoked by them, should not depend on any
dynamic global data structures, as changing such structures (and hence the
instantiations of the rule) will be invisible to the inference engine."
I read this as saying I should not write a rule like this, where *COUNTER*
can be modified outside of the inference engine:
(defvar *counter* 0)
(defrule busted-rule
:forward
(some-fact ? count ?count)
(test (> ?count *counter*))
-->
...)
Makes sense to me. However, what about hash table lookups?
(defvar *table* (make-hash-table))
(defun key-present-p (key)
(gethash key *table*))
(defrule frodo
:forward
(some-fact ?fact key-value ?value)
(test (not key-present-p ?value))
-->
((add-this-fact-to-table ?fact ?value)))
To me, this should work just fine.
If the latter scenario is allowed, then we've probably found a bug in KW. If
it isn't, then I don't understand why it isn't. And if it isn't, what is the
proper way to implement scenarios like this?
Thanks and Regards,
David E. Young
Bloodhound Software, Inc.
http://bloodhoundinc.com
"For wisdom is more precious than rubies,
and nothing you desire can compare with her."
-- Prov. 8:11
"But all the world understands my language."
-- Franz Joseph Haydn (1732-1809)
This email message is for the sole use of the intended recipients(s) and may contain confidential and privileged information of Bloodhound Software, Inc.. Any unauthorized review, use, disclosure is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.