Hi everybody,
Is there a way to make Kenny Tilton's cells library notice when a hash
table is updated?
For example:
;; Let's set up
(defmodel table-model ()
((table :accessor table :initform (c-in (make-hash-table)))))
(def-c-output table ((self table-model))
(format t "table was changed"))
(defparameter *tm* (make-instance 'table-model))
*TM*
;; check
(setf (table *tm*) (make-hash-table))
;; table was changed
;; #<HASH-TABLE :TEST EQL :COUNT 0 {BFA39A9}>
;; but unfortunately
(setf (gethash 1 (table *tm*)) 'sth)
;; STH
I understand that this is non-trivial since only the contents of a
cell object are changed, not the object itself. But maybe someone has
found a way around it ...
Thanks,
Peter
On Jul 8, 8:36 pm, ··················@gmail.com"
<·················@gmail.com> wrote:
> Hi everybody,
>
> Is there a way to make Kenny Tilton's cells library notice when a hash
> table is updated?
I invite you to have a look at my FSet functional collections package:
http://common-lisp.net/project/fset/
It will allow you to do what you want:
(defmodel table-model ()
((table :accessor table :initform (c-in (fset:map)))))
[... other stuff unchanged ...]
(setf (fset:lookup (table *tm*) 1) 'sth)
;; table was changed
;; STH
Why does it work? Because the `setf' method for `lookup' modifies,
not some mutable data structure, but the place which is the first
argument to `lookup'. (It has to do that to work at all; FSet
collections are immutable.)
Certainly there are other ways to solve your problem, but I couldn't
resist mentioning FSet because this situation you are in -- of wanting
demon methods to be triggered when a collection-valued slot is updated
--
is part of what convinced me that the mutable collections we have all
been using all these years are suboptimal.
-- Scott
·················@gmail.com wrote:
> Hi everybody,
>
> Is there a way to make Kenny Tilton's cells library notice when a hash
> table is updated?
>
> For example:
>
> ;; Let's set up
> (defmodel table-model ()
> ((table :accessor table :initform (c-in (make-hash-table)))))
>
> (def-c-output table ((self table-model))
> (format t "table was changed"))
You surprise me here, I thought you would want:
(def-hash-value-observer <key> <table>....)
...not an unspecific observer on the whole table. Anyway..
>
> (defparameter *tm* (make-instance 'table-model))
> *TM*
>
> ;; check
> (setf (table *tm*) (make-hash-table))
> ;; table was changed
> ;; #<HASH-TABLE :TEST EQL :COUNT 0 {BFA39A9}>
>
> ;; but unfortunately
> (setf (gethash 1 (table *tm*)) 'sth)
> ;; STH
>
> I understand that this is non-trivial...
Depends on the value of trivial. I would say it is a straightforward
exercise, having done frightening things with the AllegroStore
persistent object database.
... since only the contents of a
> cell object are changed, not the object itself. But maybe someone has
> found a way around it ...
(a) Hire Kenny. He will...
(b) ...write some glue. This will...
(c) ...cost you a little transparency because I think a little API is
necessary -- mebbe a "direct-lookup-table data structure or CLOS class
to hold the glue internals and implementation (in this case a hash
table) and then a DIRECT-VALUE accessor that triggers
dependency/propagation).
It is definitely a job requiring internals work, but the kind where you
just learn how it works and then work from existing bits and pieces.
kt