[cells-devel] Re: chat-server using cells?

Ken Tilton kentilton at gmail.com
Tue Jun 13 02:13:07 UTC 2006


On 6/12/06, Lars Rune Nøstdal <larsnostdal at gmail.com> wrote:
>
> ok, after some mailing with Kenny - this works:
>
>
> (defpackage CellsChat
>   (:use :cl :cells))
> (in-package :CellsChat)
>
>
> (defparameter *newline* (princ-to-string #\Newline))
>
>
>
> (defmodel Participant ()
>   ((chat :cell nil :accessor chat-of :initarg :chat
>          :initform (error "Participants need something for its
> `chat'-slot."))
>
>    (username :cell nil :accessor username-of :initarg :username
>              :initform (error "CellsChat needs a `username'."))
>
>    (speech :cell :ephemeral :accessor speech-of :initarg :speech
>            :initform (c-in nil))))
>
>
>
> (defmethod initialize-instance :after ((participant Participant) &key)
>   (push participant (participants-of (chat-of participant))))
>
>
>
> (defobserver speech ((participant Participant))
>   ;; `new-value' always refers to the slot `speech'
>   ;; since that is what we're observing
>   (when new-value
>     (dolist (participant (participants-of (chat-of participant)))
>       (format t "Update interface for '~A', appending: ~A~%"
>               (username-of participant) new-value))))
>
>
>
> (defmethod say ((participant Participant) (what string))
>   (setf (speech-of participant)
>         (concatenate 'string (username-of participant) ": " what
> *newline*)))
>
>
>
> (defmodel Chat ()
>   ((text-box :accessor text-box-of
>              :initform (c? (concatenate 'string
>                                         ;; conversation till now..
>                                         (or .cache "")
>                                         ;; well, ok then - this is neat
> O_o
>                                         (some 'speech-of
> (participants-of self)))))
>
>    (participants  :accessor participants-of
>                   :initform (c-in nil))))
>
>
>
> (defun testChat ()
>   (let* ((chat (make-instance 'Chat))
>          (user1 (make-instance 'Participant :username "user1" :chat chat))
>          (user2 (make-instance 'Participant :username "user2" :chat
> chat)))
>     (say user1 "Hello, anyone here?")
>     (say user2 "Well hello there - I'm here :)")
>     (say user1 "Cool .. what's up?")
>     (say user2 "Just doing some Lisp-hacking -- you?")
>     (say user1 "Naaaw .. nothing; I'm kind of tired, so I'm just
> sitting in the sun here listening to some music")))
>
>
> ..pretty darn cool :)


yes, indeed, except for the bug I tricked Lars into copying. It was a new
one on me, to tell you the truth. I am working on a write-up. Almost done,
then I will post it here. The bug can be seen by printing out the contents
of the text-box (supposedly a full log) at the end of the chat:

user1: Hello, anyone here?
user2: Well hello there - I'm here :)
user2: Just doing some Lisp-hacking -- you?

In brief, SOME and ephemerals do not play well together.

New instances get pushed onto participants (the slot), so user appears
before user1 in the list. Once user2 gets picked up by SOME, there is no
dependency on user1 speech, so only user2 gets recorded. Recall that
dependencies reflect only the most recent evaluation (uhhh--I think synapses
are an exception, but I have started to wonder why <g>. Anyway....).

Deets to follow. Interestingly, I think this is the first case where the
Lisp one might naturally write does not Just Work. This bothers me quite a
bit -- it may be a Bad Sign. After I post the writeup I will be interested
in what others think.

kt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cells-devel/attachments/20060612/dd118804/attachment.html>


More information about the cells-devel mailing list