Hi David -
A suggestion to make the retrieve macro more powerful:
Currently, it is only possible to do queries which retrieve
instances, but not facts or slot values. By replacing
,(find-instance-of var) with ,var we'll be able to retrieve
instances and facts, as well as slot values:
(retrieve2 (?inst) (a (:object ?inst))) ;; different syntax,
but we can still get instances
(retrieve2 (?fact) (?fact ?a)) ;; get fact objects
(retrieve2 (?slotval) (a (s1 ?slotval)) (b (s2 ?slotval))) ;;
get slot values
Here's the code:
(defmacro retrieve2 ((&rest varlist) &body body)
(flet ((make-query-binding (var)
`(cons ',var ,var))) ;; just ,var instead of ,(find-
instance-of var)
(let ((query-name (gensym))
(query (gensym)))
`(with-inference-engine ((make-query-engine
(inference-engine)))
(let* ((,query-name (gensym))
(,query
(defquery ',query-name
(query-fact)
,@body
=>
(push (list ,@(mapcar #'make-query-
binding varlist))
*query-result*))))
(run-query ,query))))))
Aneil
(aneil@hms.harvard.edu)
Logged In: YES
user_id=21258
This is an excellent suggestion, and will make the change.
As an aside, RETRIEVE as implemented is somewhat transient.
Eventually I would like to add a prolog-style backward
chaining interpreter to Lisa and use it to implement a more
powerful query mechanism.