[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Run Time manipulation of Common Lisp Places



One problem I have always had is trying to make general lisp
constructs that understand places. Here goes an example:

I want to define a new class EDITABLE-PLACE-DIALOG-ITEM that
displays a place (the value of a global variable, the slot value
of an instance, etc) and automaticaly updates it when the user
changes the text of the dialog item.

I found that these kind of problems reocur time and time again
when you try to devellop general macintosh interface classes.

The best solution I managed is the following:

(defstruct PLACE
  reader
  writer)

(defun GET-PLACE (place)
  (funcall (place-reader place)))

(defun SET-PLACE (place value)
  (funcall (place-writer place)
           value))

(defsetf GET-PLACE set-place)

(defmacro PLACE (form)
  (let ((value (gensym)))
    `(make-place
      :reader (function (lambda () ,form))
      :writer (function (lambda (,value) (setf ,form ,value))))))

You can then simply call
(make-instance 'editable-place-dialog-item
  :place (place *foo*))
(make-instance 'editable-place-dialog-item
  :place (place (slot-value *bar* 'my-slot)))

This works great, but the drawback is that every place that I
define this way includes two compiled functions. This seems a bit
extravagant.

Did I miss something?
Does any of you had the same problems?
Any suggestions?
Thanks.

Guillaume Cartier
LACIM, Universite du Quebec a Montreal.
Bureau: (514) 987-4290
E-Mail: cartier@math.uqam.ca