[gambit-list] Spork & Session variables
Per Eckerdal
per.eckerdal at gmail.com
Sun Sep 27 04:50:44 EDT 2009
Here's an example that uses session variables:
(define c (spork-serve port: 8088))
(define var (make-session-variable "[NOT INITED]"))
(add-spork c ("")
(basic-template
`(h1 "Value: " ,(var))
`(a (@ (href "edit-value")) "Edit value")))
(add-spork c ("edit-value")
(let* ((ret (show
(lambda (url)
(basic-template
`(form
(@ (method "POST")
(action ,url))
(input (@ (type "text")
(name "value")))
(input (@ (type "submit"))))))))
(value-pair (assoc "value" ret))
(value (and value-pair
(cdr value-pair))))
(var (or value "[NO VALUE]"))
(goto "/")))
The web app should be accessible at http://localhost:8088/ Not the
most beautiful code around, but for me it works.
Using the session variable from the REPL won't work, because you are
not inside of an HTTP request; In Spork's implementation of session
variables, accessing or editing a session variable from the REPL is
nonsensical. It might be useful to add functions to change the dynamic
environment to a certain session, but I haven't done that yet.
/Per
26 sep 2009 kl. 15.24 skrev Nicola Archibald:
> Has anyone had any success with using session variables within spork?
> The only real documentation for session variables is within the
> blackhole-libs docs, which state to just (define variable
> (make-session-variable)) which should give the default value of #f to
> the variable... But doing so raises exceptions in 'cookie-get-changes'
> whenever attempting to read or write the variable (using (variable)
> and
> (variable value) respectively, of course).
>
> If anyone has gotten them working can they share insights? or if
> Per/Mickael has any suggestions?
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
More information about the Gambit-list
mailing list