From: ··@frank-buss.de
Subject: Cells decrypted
Date: 
Message-ID: <1175627944.881622.83980@y80g2000hsf.googlegroups.com>
Kenny keeps telling about the spreadsheet idea for explaining the
declarative dataflow paradigm, so I decided to use this as an example
for start learning how to use Cells. It is based on
http://www.common-lisp.net/project/cells/asdf-install/cells_2.0.tar.gz
, which maybe not the latest source, but I don't want to spend some
more hours to figure out how to use get an anonymous CVS account
(hint: a new release would be a good idea, if it is outdated).

First unpack the archive somewhere. If you have ASDF installed, you
can load Cells like this (assuming you have unpacked it in /tmp)

(push "/tmp/cells_2.0/" asdf::*central-registry*)
(asdf:oos 'asdf:load-op :cells)

Anything in the following example will be defined in the cells package
itself:

(in-package :cells)

Now the idea is to create a spreadsheet with two cells, which are
added on changes and can be read from a third cell.

(defmodel sum ()
  ((a :cell t :initarg :a :initform (c-in 0) :accessor a)
   (b :cell t :initarg :b :initform (c-in 0) :accessor b)
   (result :cell t :initarg :result :initform 0 :accessor result))
  (:default-initargs
   :result (c? (+ (^a) (^b)))))

"result" is updated whenever "a" or "b" is changed. In Cells you have
to specify "(c-in)" for input values, where the argument is the
initial value. All cells, input or output values, must be declared
with ":cell t".

For calculating output values, you have to write it in a ":default-
initargs" block, where the name of the value is a keyword and if you
want to calculate the value based on other cell values, you have to
use "c?". For referencing cells, you have to write it in parantheses
and prefix it with "^" (to the Cells gurus: please correct me, if I
didn't understand it correctly).

The rest is like CLOS.

Let's test it (note: if you don't get the right results, try a "(cell-
reset)", first. I had the problem after running some outdated example,
that every value returned just a quote, but I can't reproduce it)

CELLS > (defparameter *sum* (make-instance 'sum))
*SUM*

CELLS > (result *sum*)
0

CELLS > (setf (b *sum*) 2)
2

CELLS > (result *sum*)
2

CELLS > (setf (a *sum*) 3)
3

CELLS > (result *sum*)
5

First we create a new instance of the sum class. The initial value for
"result" is 0. After changing cell "b" to 3, "result" becomes 3, too.
Finally after changing "a" to 2, "result" becomes 5.

Another nice feature are callbacks on value changes. E.g. if you
really want to write a spreadsheet, it would be nice to be notified
which fields have changed, so that they can be redrawn, instead of
redrawing everything. This can be done with def-c-output (there are
some magic variables available inside it, new-value is one of it and
it is the value, which the cell become, after the callback function
returned)

(def-c-output result ((self sum))
  (format t "current result: ~d" new-value))

Now the function is called, if you change anything, which changes the
value of "result":

CELLS > (setf (a *sum*) 7)
current result: 9
7

--
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de

From: Ken Tilton
Subject: Re: Cells decrypted
Date: 
Message-ID: <jVzQh.224$xa6.60@newsfe12.lga>
··@frank-buss.de wrote:
> Kenny keeps telling about the spreadsheet idea for explaining the
> declarative dataflow paradigm, so I decided to use this as an example
> for start learning how to use Cells. It is based on
> http://www.common-lisp.net/project/cells/asdf-install/cells_2.0.tar.gz
> , which maybe not the latest source, but I don't want to spend some
> more hours to figure out how to use get an anonymous CVS account
> (hint: a new release would be a good idea, if it is outdated).

Hint: for any c-l.net project using CVS, the top-level c-l.net page has 
a little link to "Repositories". Choose "Cells" if you can find the 
project pull-down menu, and then you are here:

     http://common-lisp.net/cgi-bin/viewcvs.cgi/?root=cells

There you will see Cells, Celtk, and a use-case contrib, cl-6502, a 
Cells Inside(tm) assembler (written against an older version of Cells). 
c-l.net has CVS set up to do nightly tarballs. Navigate down into the 
Cells /module/ and look for the tarball.

> 
> First unpack the archive somewhere. If you have ASDF installed, you
> can load Cells like this (assuming you have unpacked it in /tmp)
> 
> (push "/tmp/cells_2.0/" asdf::*central-registry*)
> (asdf:oos 'asdf:load-op :cells)
> 
> Anything in the following example will be defined in the cells package
> itself:
> 
> (in-package :cells)
> 
> Now the idea is to create a spreadsheet with two cells, which are
> added on changes and can be read from a third cell.
> 
> (defmodel sum ()
>   ((a :cell t :initarg :a :initform (c-in 0) :accessor a)
>    (b :cell t :initarg :b :initform (c-in 0) :accessor b)
>    (result :cell t :initarg :result :initform 0 :accessor result))
>   (:default-initargs
>    :result (c? (+ (^a) (^b)))))
> 
> "result" is updated whenever "a" or "b" is changed. In Cells you have
> to specify "(c-in)" for input values, where the argument is the
> initial value. All cells, input or output values, must be declared
> with ":cell t".

:cell t is the default in cells3, btw.

> 
> For calculating output values, you have to write it in a ":default-
> initargs" block, 

...or the initform value or it can be specified as an initarg to 
make-instance.

> where the name of the value is a keyword and if you
> want to calculate the value based on other cell values, you have to
> use "c?". For referencing cells, you have to write it in parantheses
> and prefix it with "^" (to the Cells gurus: please correct me, if I
> didn't understand it correctly).

The (^my-field) is now a no-arg macro and should be a symbol-macro so it 
is also no-parens. It expands simply to (my-field self).

> 
> The rest is like CLOS.
> 
> Let's test it (note: if you don't get the right results, try a "(cell-
> reset)", first. I had the problem after running some outdated example,
> that every value returned just a quote, but I can't reproduce it)
> 
> CELLS > (defparameter *sum* (make-instance 'sum))
> *SUM*
> 
> CELLS > (result *sum*)
> 0
> 
> CELLS > (setf (b *sum*) 2)
> 2
> 
> CELLS > (result *sum*)
> 2
> 
> CELLS > (setf (a *sum*) 3)
> 3
> 
> CELLS > (result *sum*)
> 5
> 
> First we create a new instance of the sum class. The initial value for
> "result" is 0. After changing cell "b" to 3, "result" becomes 3, too.
> Finally after changing "a" to 2, "result" becomes 5.
> 
> Another nice feature are callbacks on value changes. E.g. if you
> really want to write a spreadsheet, it would be nice to be notified
> which fields have changed, so that they can be redrawn, instead of
> redrawing everything. This can be done with def-c-output (there are
> some magic variables available inside it,..

No, the default parameter names are:
     (self new-value old-value old-value-supplied)

You can change those, in this case to new-dum old-sum if you think it 
makes your code more readable.

>... new-value is one of it and
> it is the value, which the cell become, after the callback function
> returned)
> 
> (def-c-output result ((self sum))
>   (format t "current result: ~d" new-value))
> 
> Now the function is called, if you change anything, which changes the
> value of "result":
> 
> CELLS > (setf (a *sum*) 7)
> current result: 9
> 7
> 
> --
> Frank Buss, ··@frank-buss.de
> http://www.frank-buss.de, http://www.it4-systems.de
> 

Thanks for the effort, but did you not find all that in cell-basics.lisp 
or Bill's Most excelent Cells Intro? here:

   http://www.tilton-technology.com/cells_top.html

Cheers, ken

-- 

"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts

"Stand firm in your refusal to remain conscious during algebra."
    - Fran Lebowitz

"I'm an algebra liar. I figure two good lies make a positive."
    - Tim Allen

"Algebra is the metaphysics of arithmetic." - John Ray

http://www.theoryyalgebra.com/
From: Ken Tilton
Subject: Re: Cells decrypted
Date: 
Message-ID: <25AQh.225$xa6.137@newsfe12.lga>
Ken Tilton wrote:
> 
> 
> ··@frank-buss.de wrote:
> 
>> Kenny keeps telling about the spreadsheet idea for explaining the
>> declarative dataflow paradigm, so I decided to use this as an example
>> for start learning how to use Cells. It is based on
>> http://www.common-lisp.net/project/cells/asdf-install/cells_2.0.tar.gz
>> , which maybe not the latest source, but I don't want to spend some
>> more hours to figure out how to use get an anonymous CVS account
>> (hint: a new release would be a good idea, if it is outdated).
> 
> 
> Hint: for any c-l.net project using CVS, the top-level c-l.net page has 
> a little link to "Repositories". Choose "Cells" if you can find the 
> project pull-down menu, and then you are here:
> 
>     http://common-lisp.net/cgi-bin/viewcvs.cgi/?root=cells

Navigate into there and you can find the cells-manifesto.txt:

 
http://common-lisp.net/cgi-bin/viewcvs.cgi/cells/cells-manifesto.txt?root=cells&view=markup

No examples, see Celtk for that.

hth, kzo

-- 

"As long as algebra is taught in school,
there will be prayer in school." - Cokie Roberts

"Stand firm in your refusal to remain conscious during algebra."
    - Fran Lebowitz

"I'm an algebra liar. I figure two good lies make a positive."
    - Tim Allen

"Algebra is the metaphysics of arithmetic." - John Ray

http://www.theoryyalgebra.com/
From: ··@frank-buss.de
Subject: Re: Cells decrypted
Date: 
Message-ID: <1175663048.242732.60250@w1g2000hsg.googlegroups.com>
On 3 Apr., 23:44, Ken Tilton <····@theoryyalgebra.com> wrote:
>      http://common-lisp.net/cgi-bin/viewcvs.cgi/?root=cells

Thanks, but how can I be sure, that the current repository files are
stable? I like more formal releases.

> Thanks for the effort, but did you not find all that in cell-basics.lisp
> or Bill's Most excelent Cells Intro? here:
>
>    http://www.tilton-technology.com/cells_top.html

Let's try it:

...
CELLS > (def-c-echo status ((self motor))
  (trc "motor status changing from" old-value :to new-value))

Error: Syntactic error in form ((SELF MOTOR)):
   Illegal function name (SELF MOTOR).
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other
options


Ok, at the bottom there is a comment that the code above doesn't work
and there is a later version. Trying this...

CELLS > (defobserver status ((self motor))
  (trc "motor status changing from" old-value :to new-value))

Error: Syntactic error in form ((SELF MOTOR)):
   Illegal function name (SELF MOTOR).
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

Type :b for backtrace, :c <option number> to proceed,  or :? for other
options


So, no, I can't find it in blog. But you are right, looks like the
example in doc/01-Cells-basic.lisp works, but it didn't look like a
simple "hello world" program for me. Writing my own simple demo was
useful to be sure that I understood it.

--
Frank Buss, ··@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de