Hi,
I don't know if that has been discussed yet, but I've several use cases where I want to do sth. like that: A cell should be calculated by a formula if it isn't set to a value. I thought that's possible with (c-formula (:inputp t) ... ), which does calculate the slot by a formula and can be setf, but how is it possible to unset the setf value and let cells calculate it again?
Example: A textbox is by default calculated by a formula. If the user enters sth. into it, that value is used. If the user clears the field of his input, the value should be calculated again.
Maybe the c-formula ... approach is completely the wrong way or that's not possible at all. I've read the documentation and primer but couldn't find anything helpful. Sorry, I'm new to cells.
Cheers, Bastian
Bastian Müller wrote:
Hi,
I don't know if that has been discussed yet, but I've several use cases where I want to do sth. like that: A cell should be calculated by a formula if it isn't set to a value. I thought that's possible with (c-formula (:inputp t) ... ), which does calculate the slot by a formula and can be setf, but how is it possible to unset the setf value and let cells calculate it again?
Example: A textbox is by default calculated by a formula. If the user enters sth. into it, that value is used. If the user clears the field of his input, the value should be calculated again.
Could you just have?:
(or (user-entered-value self) (calculated-value self))
One thing not clear to me is how you know they first indicate they want to enter a value and then communicate that they have decided against, and those things really come into play.
Lemme know and I'll tell you how I would handle it.
Pretty much I would avoid SETF as much as possible and end up with something still formulaic:
(if (user-owns-value self) (editor-result self (key-input self)) (application-decides-value self))
Maybe the c-formula ... approach is completely the wrong way or that's not possible at all. I've read the documentation and primer but couldn't find anything helpful. Sorry, I'm new to cells.
No problem. This is a common case where one really wants to think procedurally and it gets to be a little fun thinking declaratively. But really the interesting part is this change from user-owning to application-owning mode, so lemme know your protocol for that and I will do what I can.
btw, as Jakub suggested often it is easier to divide and conquer:
(or (user-value self) (application-decided-value self))
...but I think you will end up with the same issue at some point of needing to know what state the field is in, so tell me more and I'll give it a shot.
cheers, ken
ps. might make a good use case. k
Hi Bastian,
Am 15.02.2009 um 16:23 schrieb Bastian Müller:
Hi,
I don't know if that has been discussed yet, but I've several use cases where I want to do sth. like that: A cell should be calculated by a formula if it isn't set to a value. I thought that's possible with (c-formula (:inputp t) ... ), which does calculate the slot by a formula and can be setf, but how is it possible to unset the setf value and let cells calculate it again?
Example: A textbox is by default calculated by a formula. If the user enters sth. into it, that value is used. If the user clears the field of his input, the value should be calculated again.
Maybe the c-formula ... approach is completely the wrong way or that's not possible at all. I've read the documentation and primer but couldn't find anything helpful. Sorry, I'm new to cells.
Cheers, Bastian
Hi Bastian (wow - another Cells user in Germany ;-) - We're three now)
As Kenny and Jakub have suggested one common solution I find myself using from time to time is:
(defmd frgo () (entered-value (c-in nil)) (value (c? (or (^entered-value) (computed-value)))))
(defun computed-value () ;;; Just making a simple function that fakes a computed value 'computed)
(defun test-it () (let ((self (make-instance 'frgo))) (format t "~&Entered value: ~s~%" (^entered-value)) (format t "~&Value: ~s~%" (^value))
(setf (^entered-value) 'entered) (format t "~&Entered value: ~s~%" (^entered-value)) (format t "~&Value: ~s~%" (^value))))
Cheers Frank
-- Frank Goenninger
Cell: +49 175 4321058 E-Mail: frgo@me.com
Frank Goenninger wrote:
Hi Frank,
(wow - another Cells user in Germany ;-) - We're three now)
Heh.
As Kenny and Jakub have suggested one common solution I find myself using from time to time is:
(defmd frgo () (entered-value (c-in nil)) (value (c? (or (^entered-value) (computed-value)))))
(defun computed-value () ;;; Just making a simple function that fakes a computed value 'computed)
(defun test-it () (let ((self (make-instance 'frgo))) (format t "~&Entered value: ~s~%" (^entered-value)) (format t "~&Value: ~s~%" (^value))
(setf (^entered-value) 'entered) (format t "~&Entered value: ~s~%" (^entered-value)) (format t "~&Value: ~s~%" (^value))))
That looks very good. When used with ":reader value" for the value slot and ":writer value" for the entered-value slot this works very well.
Thanks a lot!
Cheers, Bastian