[cells-devel] chat-server using cells?
Lars Rune Nøstdal
larsnostdal at gmail.com
Mon Jun 12 17:15:16 UTC 2006
Hi,
I'm trying to figure out how to design a chat-server using Cells. This
doesn't work, but this is what I've come up with:
(defpackage CellsChat
(:use :cl :cells))
(in-package :CellsChat)
(defparameter *newline* (princ-to-string #\Newline))
(defmodel CellsChat ()
((username :cell nil :accessor username-of :initarg :username
:initform (error "CellsChat needs a `username'."))
(text-box :accessor text-box-of :allocation :class
:initform (c-in ""))
(participants :cell nil :accessor participants-of :allocation :class
:initform nil)))
(defmethod initialize-instance :after ((chat CellsChat) &key)
;; New user joins the conversation.
(push chat (participants-of chat))
;; New user wants to see what's been going on recently.
(updateTextBox chat))
(defmethod updateTextBox ((chat CellsChat))
;; Show conversation till now.
(format t "(text-box-of ~A): '~A'~%"
(username-of chat)
(text-box-of chat)))
(defobserver text-box ((chat CellsChat))
;; Update interface of each participant whenever
;; `text-box' changes (for whatever reason).
(dolist (participant (participants-of chat))
(updateTextBox participant)))
(defmethod say ((chat CellsChat) (what string))
(setf (text-box-of chat)
(concatenate 'string
(text-box-of chat)
(username-of chat) ": " what *newline*)))
(defmethod part ((chat CellsChat))
;; User leaves the conversation.
(setf (participants-of chat)
(delete chat (participants-of chat))))
--
Mvh,
Lars Rune Nøstdal
http://lars.nostdal.org/
More information about the cells-devel
mailing list