Lisp HUG Maillist Archive

Knowledgework - Lisp Symbiosis

Hi all,


I have a little problem when trying to call a lisp expression inside a 
KW expression.

This is a class I've implemented:

(kw:def-kb-class facet ()
   ((name :accessor name)))

and this is a function to get instances of facet by comparing the value 
of the instance variable "name".

(defun get-facet-obj (fct)
   (kw:findall '?obj '(and (facet ?obj)
                           (equal (name ?obj) fct))))

I've solved the problem like iut's written below, but of course it's not 
  the best solution (it's to get all the object of "facet" and then 
iterate with dolist and compare the instance variable with the argument 
given to the function).

(defun get-facet-object (fct)
   (let ((current-facet nil)
         (facets-list  (kw:findall '?obj '(facet ?obj))))
     (dolist (current-facet facets-list nil)
       (if (equal (name current-facet) fct)
           (return current-facet)))))

I believe that the problem is that the call to (name ?obj) in the 
get-facet-obj function does not call "name", but instead it tries to 
equalize fct with the "structure" (the functor) (name ?obj) ! Of course 
I'm not sure of this.

Anyone has any idea of what's happening?

thanks,
Miro.





Re: Knowledgework - Lisp Symbiosis

>>>>> On Mon, 05 May 2003 14:10:48 +0200, Miro Casanova <mcasanov@vub.ac.be> said:

    Miro> I have a little problem when trying to call a lisp expression inside a
    Miro> KW expression.

    Miro> This is a class I've implemented:

    Miro> (kw:def-kb-class facet ()
    Miro>    ((name :accessor name)))

    Miro> and this is a function to get instances of facet by comparing the
    Miro> value of the instance variable "name".

    Miro> (defun get-facet-obj (fct)
    Miro>    (kw:findall '?obj '(and (facet ?obj)
    Miro>                            (equal (name ?obj) fct))))

    Miro> I've solved the problem like iut's written below, but of course it's
    Miro> not the best solution (it's to get all the object of "facet" and then
    Miro> iterate with dolist and compare the instance variable with the
    Miro> argument given to the function).

    Miro> (defun get-facet-object (fct)
    Miro>    (let ((current-facet nil)
    Miro>          (facets-list  (kw:findall '?obj '(facet ?obj))))
    Miro>      (dolist (current-facet facets-list nil)
    Miro>        (if (equal (name current-facet) fct)
    Miro>            (return current-facet)))))

    Miro> I believe that the problem is that the call to (name ?obj) in the
    Miro> get-facet-obj function does not call "name", but instead it tries to
    Miro> equalize fct with the "structure" (the functor) (name ?obj) ! Of
    Miro> course I'm not sure of this.

    Miro> Anyone has any idea of what's happening?

I think you have more or less explained it to yourself. KnowledgeWorks
uses Prolog-style unification so you need to write your code something
like:

;;; untested
(defun get-facet-obj (fct)
   (kw:findall '?obj '(facet ?obj name ,fct)))

That is you can just pattern-match on the object.

;;; or more long-winded (also untested)
(defun get-facet-obj (fct)
   (kw:findall '?obj '(and (facet ?obj name ?name)
                           (= ?name ,fct))))

HTH

__Jason


Updated at: 2020-12-10 09:00 UTC