Saving the local state means that a for-loop can be written at the language level. (The Polyglot Hello World example included with SISCweb demonstrates this feature.) Saving the stack also means that an entire navigation flow can be represented as a subroutine returning a value, rather than as a sequence of code snippets connected by GOTOs (HREFs) finally depositing a value in the global scope.
A complete treatment of parameters is available in SRFI-39. This section is concerned with the use of the dynamic environment to maintain state shared by all requests for the same user in the same execution flow.
SRFI-39 parameters are essentially dynamically-scoped
variables. They can be defined in the global or the module scope
and then bound to the dynamic scope -- the scope of the
execution flow -- in the application entry point through the
parameterize
form.
When using send-*/[suspend|forward]
, the
parameters, being part of the dynamic environment, are captured
in the suspended state -- the suspension of the program
execution is transparent to parameter bindings.
However procedures stored with
@href-p
-style attributes or the
forward/store!
procedure will run in the
base dynamic environment, and thus will see fresh values of the
parameters. In those cases on can use
forward/dynenv/store!
, which instead
preserves the dynamic environment.
The Counter with SRFI-39 Parameters example demonstrates this technique.
Requires: (import siscweb/webcells)
Web Cells are a way to track program state according to the navigation flow. They are described in full in the paper Interaction-Safe State for the Web.
In essence, cells establish a dynamic scope over the navigation path of a user. Successive pages can overshadow values of bindings set in previous pages, but do not destroy them.
If a user backtracks the browser window, previous values are again visible. If the user clones the window and proceeds through two different navigation branches, each branch sees the values it overshadows.
The Counter with Webcells example demonstrates this technique.
procedure:
(webcell/set! cell value) => undefined
Sets the content of the given
cell
to the specifiedvalue
.Of course the specified value is only accessible to the current and successive request.
Requires:
(import siscweb/session)
Located in:
siscweb.jar
The Session object can be accessed via a syntax similar to that
of SRFI-39
parameters, or via Scheme wrappers around the
Session.get/setAttribute()
calls. While the
former is appropriate for storing Scheme values, the latter is
provided as a means to store and retrieve Java objects (or
java-wrap
ped Scheme values.)
procedure:
(session/make-parameter name) => proc
(module security (define auth-token (session/make-parameter "auth-key")) ;; sets an auth token in the session object (define (login usr pwd) (auth-token (make-token usr pwd))))