[cells-devel] can one make dependencies between models?

Frank Goenninger frgo at me.com
Tue Apr 17 21:08:14 UTC 2012


Hi Mirko,

Am 17.04.2012 um 20:17 schrieb Mirko Vukovic:

> Hello,
> 
> I am doing very basic cell-stuff, much like the ones in the doc folder:  Not liking excel and its cousins, I am implementing spread-sheet like calculations in cells.
> 
> My question:
> 
> 1) Can I build two models (model1, model2) and specify that a slot in model2 depends on changes in some other slot in model1?

Sure:

(in-package #:cells)

;;; ------------------
;;; ***  Model M1  ***
;;; ------------------
  
(defmd m1 ()
  a
  b
  :a (c-in 1)
  :b (c-in 1))

(defobserver a ((self m1))
  (when new-value
    (format *debug-io* "~%~S: New value for slot a => ~S."
      self (a self))))

(defobserver b ((self m1))
  (when new-value
    (format *debug-io* "~%~S: New value for slot b => ~S."
      self (b self))))

(defmacro mk-m1 (id)
  `(make-instance 'm1
     :fm-parent *parent*
     :md-name ,id))

;;; ------------------
;;; ***  Model M2  ***
;;; ------------------

(defmd m2 ()
  (c (c? (let ((m1 (fm^ :m1)))   ;; -> fm^ searches for :m1 in the current family
           (* (a m1) (b m1))))))

(defmacro mk-m2 (id)
  `(make-instance 'm2
     :fm-parent *parent*
     :md-name ,id))

(defobserver c ((self m2))
  (when new-value
    (format *debug-io* "~%~S: New value for slot c => ~S."
      self (c self))))

;;; ------------------
;;; ***  Family M  ***
;;; ------------------

(defmd m (family)
  (kids (c? (the-kids
             (mk-m1 :m1)
             (mk-m2 :m2)))) ;; :m1 and :m2 are kids of :m's family.
  :md-name :m)

;;; -----------------
;;; ***  TESTING  ***
;;; -----------------

(defun m-test ()
  
  (let* ((self (make-instance 'm))
         (m1 (fm-find-kid self :m1)))
    
    ;; Step 1
    (format *debug-io* "~%~%STEP 1~&")
    (setf (a m1) 2)
    ;; => C = 2
    ;; See observer for C !
    
    ;; Step 2
    (format *debug-io* "~%~%STEP 2 ~&")
    (setf (b m1) 3))
    ;; => C = 6
    ;; See observer for C !
  
  (values))


> 2) Related: can I change a slot specification in a model.  For example from `c-in' to `c?'.  I assume that I can, but I would have to re-initialize the model somehow.  Correct? 

This one I'd like to leave for Kenny to answer ... Never did that during one run - I always reset cells via #'cells-reset and the started over when I needed to do that.

> I am also very interested in the question posted just a few minutes ago.  I would like to build an automated way of generating a GUI front end my cell models.

I tried to answer this in the other mail.

> 
> Thanks,
> 
> Mirko

Hope that helps.

Cheers
    Frank





More information about the cells-devel mailing list