Subject: Re: Lisp Web Development and Application State
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 02 Sep 2006 23:58:37 -0500
Newsgroups: comp.lang.lisp
Message-ID: <NdSdnXQTV6Vg_WfZnZ2dnUVZ_sCdnZ2d@speakeasy.net>
mrcsparker@gmail.com <mrcsparker@gmail.com> 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 "closures...save 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.


-Rob

[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:

      <http://groups.google.com/group/comp.lang.lisp/tree/browse_frm/thread/25a9a0b117e725e1/c3b89e08206f9298?rnum=51&_done=%2Fgroup%2Fcomp.lang.lisp%2Fbrowse_frm%2Fthread%2F25a9a0b117e725e1%2Fa49a359a1461a39b%3Ftvc%3D1%26#doc_b39acefc408ff0e3>

    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:

      <http://groups.google.com/group/comp.lang.lisp/msg/a8b1346d10ef53b6?as_umsgid=j4GdnazAuoV9MEfZnZ2dnUVZ_t2dnZ2d@speakeasy.net>

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607