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? 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?
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.
Thanks,
Mirko
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:
- 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))
- 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
... Output of the short demo below:
(m-test)
M1: New value for slot a => 1. M1: New value for slot b => 1. M2: New value for slot c => 1.
STEP 1
M1: New value for slot a => 2. M2: New value for slot c => 2.
STEP 2
M1: New value for slot b => 3. M2: New value for slot c => 6.
... cute, ha ?
;-)))
Frank
Am 17.04.2012 um 23:08 schrieb Frank Goenninger:
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:
- 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))
- 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
Thank you very much Frank, I think I got it.
A follow-up question. With this technique, I have several models, and the data is flowing from one model to the next. Nice.
But is there a suggested procedure to temporarily isolate the model, so that it can be tested by itself? In other words, can one explicitly set values to cells whose initform defines them in terms of other model's slots.
I tried setf on a cell that was linked to another model. It seems to work.
But, is its initform (c? (let ((m (fm^ :other-model))) (blah (slot m) ...))) still active? How can I test that? By forcing that model to recompute itself. How do I do that? I did not find an obvious candidate in the exported symbols.
Thanks again,
Mirko
On Tue, Apr 17, 2012 at 5:13 PM, Frank Goenninger frgo@me.com wrote:
... Output of the short demo below:
(m-test)
M1: New value for slot a => 1. M1: New value for slot b => 1. M2: New value for slot c => 1.
STEP 1
M1: New value for slot a => 2. M2: New value for slot c => 2.
STEP 2
M1: New value for slot b => 3. M2: New value for slot c => 6.
... cute, ha ?
;-)))
Frank
Am 17.04.2012 um 23:08 schrieb Frank Goenninger:
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:
- 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))
- 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
Am 18.04.2012 um 05:29 schrieb Mirko Vukovic:
But is there a suggested procedure to temporarily isolate the model, so that it can be tested by itself? In other words, can one explicitly set values to cells whose initform defines them in terms of other model's slots.
I tried setf on a cell that was linked to another model. It seems to work.
How exactly did you do the setf ?
But, is its initform (c? (let ((m (fm^ :other-model))) (blah (slot m) ...))) still active?
What does the inspection of your model and the cells slot reveal ?
How can I test that? By forcing that model to recompute itself. How do I do that? I did not find an obvious candidate in the exported symbols.
Recalculation is simply forced by "reading" / accessing a cells slot... As soon as you say (c? (some-slot model)) or even just do a (format ..."~s" (some-slot model)) this triggers a recompute cycle in cells - the slot needs to be current to be correct so Cells triggers all dependencies...
Thanks again,
Mirko
Frank
On Tue, Apr 17, 2012 at 5:13 PM, Frank Goenninger frgo@me.com wrote: ... Output of the short demo below:
(m-test)
M1: New value for slot a => 1. M1: New value for slot b => 1. M2: New value for slot c => 1.
STEP 1
M1: New value for slot a => 2. M2: New value for slot c => 2.
STEP 2
M1: New value for slot b => 3. M2: New value for slot c => 6.
... cute, ha ?
;-)))
Frank
Am 17.04.2012 um 23:08 schrieb Frank Goenninger:
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:
- 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))
- 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
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 used cells-gtk3 for exactly this purpose, i.e. linking the position/text/color of graphic elements to the state of cells models.
Depending on your objectives, some of the more complex widgets might be very helpful: - a treeview that reflects a hierarchical object structure (supporting drag and drop if I recall correctly) - a listview (grid) that shows slots of models in a list (can even be editable) - a canvas (based on cairo) that can be populated by visual primitives (boxes, circles, lines, text fields) that mirror cells models (e.g. start point of a line can be linked to the position of a box, and if the user drags/drops the box, the line follows like a connector)
Let me know if you have further questions. I wrote a fairly complex application using cells/cells-gtk (including a simple physics simulator using cells-ode and opengl), and I'm happy to dig up sample code if needed.
Peter
Thanks,
Mirko
cells-devel site list cells-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/cells-devel
Thanks Peter.
That activity is still in the future. But from my own historical perspective, the very reason I switched to lisp several years ago was the desire for such self-GUI-fying models. I had a blast lisping, but never got to this original goal :-)
On Tue, Apr 17, 2012 at 6:57 PM, Peter Hildebrandt < peter.hildebrandt@gmail.com> wrote:
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 used cells-gtk3 for exactly this purpose, i.e. linking the position/text/color of graphic elements to the state of cells models.
Depending on your objectives, some of the more complex widgets might be very helpful:
- a treeview that reflects a hierarchical object structure (supporting
drag and drop if I recall correctly)
- a listview (grid) that shows slots of models in a list (can even be
editable)
- a canvas (based on cairo) that can be populated by visual primitives
(boxes, circles, lines, text fields) that mirror cells models (e.g. start point of a line can be linked to the position of a box, and if the user drags/drops the box, the line follows like a connector)
Let me know if you have further questions. I wrote a fairly complex application using cells/cells-gtk (including a simple physics simulator using cells-ode and opengl), and I'm happy to dig up sample code if needed.
Peter
Thanks,
Mirko
cells-devel site list cells-devel@common-lisp.net http://common-lisp.net/mailman/listinfo/cells-devel