next up previous contents
Next: Requesting Information from the Up: Calling Lisp and the Previous: Returning Values from Lisp

The List of Values in a Slot

Algernon normally treats a value b in the slot p of a frame a as an abbreviation for the logical predicate p(a,b). However, there are times when it is useful to have the list of values ( tex2html_wrap_inline1349 tex2html_wrap_inline1351 ... tex2html_wrap_inline1353 ) in a given Algernon slot.

tabular604

In the following, we obtain the list of Adam's children in order to print it out.

  (ask '((:bind ?kids (:values Adam child))
         (:eval (format t "~%Adam's children are ~a." '?kids)))
       :comment ":BIND the list of values in a slot.")

QUERYING:  :BIND the list of values in a slot.

Adam's children are (ELLEN DONNA CHARLES).

 Result:
   Binding:             ?kids  --- (ellen "[ellen]" donna "[donna]" charles "[charles]")
                       
  => T

We can also obtain the list of values in a slot to pass it to a Lisp function to compute some other value, in this case, the number of elements.

  (ask '((:bind ?n (:funcall #'length (:values Adam child)))
         (:eval (format t "~%Adam has ~a children." '?n)))
       :collect '(Adam has ?n children)
       :comment ":BIND and :FUNCALL evaluate a Lisp function")

QUERYING:  :BIND and :FUNCALL evaluate a Lisp function

Adam has 3 children.

 Result:
   Binding:             ?n     --- 3
                       
  => ((ADAM HAS 3 CHILDREN))



Micheal S. Hewett
Tue Oct 29 10:54:13 CST 1996