Subject: Re: Lisp Web Development and Application State
From: (Rob Warnock)
Date: Sat, 02 Sep 2006 23:58:37 -0500
Newsgroups: comp.lang.lisp
Message-ID: <> <> wrote:
| How do people around here save state in Lisp-based web apps?  I have
| been playing around with tbnl/cl-who, but most of the stuff I have been
| doing is pretty standard.  I want to put together a form application
| that lets me easily create multi-page forms where the back-button works.

Well, from one point of view, it's not so much the "Back" button per se
that's the problem, but the "Reload/Refresh" and "Forward" buttons.  ;-}

| I have looked at UCW and read Paul Graham's writings on ViaWeb.
| UCW is great, and PG's stuff would work if I spawned a new process
| for each user (closures with multiple users and one lisp process are,
| well, closures.  They save one state).

Not necessarily. See the recent long thread here[1] that eventually
got around to an interesting discussion of "web continuations"[2]
with a complaint by me about needing multiple continuations [that
mirrors your " one state" complaint] and a delightful
response by Anton van Straaten showing a simple way to provide a web
page with multiple continuations by constructing them all before
painting the page [and then abandoning the default continuation for
the page, which is the clever bit].

| So, how would you build a simple web application that saves state
| between pages in Lisp?

Hidden variables in the HTML forms, that is, <INPUT TYPE="hidden"
NAME="state" VALUE="8NM83gdUrqI8TsHe"> or similar. These provide
the hook for you to map back to wherever on the server you stored
the full state [whether in memory or an SQL database or whatever],
as I showed previously.[3]

In the limit, this can extend so far as to store *all* of the state
in the displayed pages, which has the distinct advantage of not
needing to handle any timeouts on session state on the server,
as well as allowing pages to be "restarted" even after having been
saved to the user's local disk(!) [but in that case you will probably
want to store a cryptographically-secure hash with the state to avoid
modify/replay attacks.


[1] Under the somewhat flamebait subject "Lisp or Scheme?".

[2] The meat of the "web continuations" portion started at about
    message #53 or so, with a post by Ken Tilton near here:


    containing the phrase "Face it, a continuation is just a cute trick
    for managing state", and then the dsicussion that followed.

[3] An article of mine about three weeks ago:


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607