Wednesday, June 25th, 2008

SymbolicWeb: Ajax and Comet with Lisp

Category: Framework

No matter how much Paul Graham talks about his Web success, we don’t hear too often about Lisp-powered Web applications.

SymbolicWeb is offering up a new type of framework to help change that.

SymbolicWeb aims to create a GUI framework similar to GTK+ and QT for Common Lisp. It differs in that it uses the browser to render the UI elements.

There are a slew of examples, such as this simple echo chat program:

[lisp]
;;;; http://nostdal.org/ ;;;;

(in-package #:sw)

(defparameter *max-chat-pane-size* 100)

(defapp chat-app (empty-page-app)
((input (mk-text-input))
(chat-pane :allocation :class (mk-container nil))))

(defuri chat-app “chat”)

(defmethod main ((chat-app chat-app))
(with-slots (input chat-pane) chat-app
(setf (on-enterpress-of input
:callback-data `((:input-value . ,(js-code-of (value-of input)))) ;; Include some data when the event fires.
:js-after (js-code-of (setf (value-of input) “”))) ;; Clear the input field after the event has been fired and sent.
(lambda (&key input-value)
(prepend (mk-span (escape-for-html input-value) :display “block”)
chat-pane)
;; Don’t let it grow too big; delete some chat history.
(when (> (length (children-of chat-pane)) *max-chat-pane-size*)
(dolist (span (subseq (children-of chat-pane) *max-chat-pane-size*))
(remove span)))))
(add-to *root*
(mk-span (who (:p “Type something in and press enter. New content is added at the top.”)))
input
chat-pane)))
[/lisp]

Posted by Dion Almaer at 5:00 am
7 Comments

+++--
3.7 rating from 30 votes

7 Comments »

Comments feed TrackBack URI

If that is the best example they can put together, I have no fear of needing to learn LISP.

Comment by Jon Hartmann — June 25, 2008

oh please no, why do we make easy things difficult.

Comment by gtwiz — June 25, 2008

Using CLOS looks like the kiss of death. I’ve seen a couple big programs that got refactored to use CLOS, but I’ve never seen a small program use CLOS and survive. CLOS is just too unwieldy at that stage — if you want a big industrial-strength object system, at the cost of making your program harder to work with, we’ve got plenty of other languages like that already.

This is Lisp syntax, but without using any of the features that make Lisp awesome.

Comment by JustAVisitor — June 25, 2008

cool .. some feedback :)

..i’m not forcing the user to use clos; the widgets use them, but other than that it’s just plain lisp — whatever the user wants to use..

ok, so how would you guys express something like this, ideally, using “lisp syntax”?

..i’d _really_ like to know .. email me if you cba. posting here: larsnostdal@gmail.com

Comment by lnostdal — June 25, 2008

..oh, or post it on the forum even:
http://groups.google.com/group/symbolicweb

..but again; i’m really not forcing the user to use CLOS .. the INPUT and CHAT-PANE slots could just be a variables in a LET or whatever..

..callbacks are just regular lambdas; not CLOS methods etc…

..that chat thing could be constructed in real-time by playing in the REPL or temporary buffers also, of course.. ..that’s how i work with or construct programs in SW actually

Comment by lnostdal — June 25, 2008

..and i’d like to see how you (non-lispers, it seems) guys at the top of the comments here express something like this in your languages..

..keeping in mind that this is the entire chat program (meaning no need for extra client side code from the user) .. if you can do better (which i doubt actually) i’ll copy you or your framework’s style :)

Comment by lnostdal — June 25, 2008

Interesting idea to use Lisp!

Not sure it’ll take off, I’m sticking to StreamHub Ajax / Comet Server for now.

Lisp and the web…hmm.

Comment by CometDude — October 1, 2009

Leave a comment

You must be logged in to post a comment.