[plt-scheme] Web cells Demo ("Interaction Safe State")

From: Christoph Schmalhofer (christoph.schmalhofer at gmx.net)
Date: Fri Nov 17 12:02:37 EST 2006

Hi all,

I struggled to understand the interaction of send/suspend continuations 
with Web cells.

So I "ported" the example application in Section 4.2
(http://www.cs.brown.edu/~sk/Publications/Papers/Published/mk-int-safe-state-web) 
to version 352 and added some tracing.

Playing around with the Demo (refresh, clone, open in new tab, watching 
the trace and knowing the *frame-stack* is a parameter really helps in 
understanding how it works.

I added continuation marks to demonstrate the difference of dynamic and 
history scope (= "scope over a dynamic 
                                   tree of Web interactions").

Have fun,
Christoph

;;--------------------------

(require (lib "unitsig.ss")
	 (lib "servlet-sig.ss" "web-server")
	 (lib "web-cells.ss" "web-server")
	 (lib "contract.ss")
	 (lib "string.ss")
	 )

(unit/sig () (import servlet^)

   ;;helpers
   (define (eprintf fmt . args)
     (apply fprintf (current-error-port) fmt args)
     (newline))


   (define stackkey 100)
   (define (new-stackkey)
     (set! stackkey (add1 stackkey))
     stackkey)

   (define (extract-current-continuation-marks key)
     (continuation-mark-set->list
      (current-continuation-marks)
      key))
   ;;


   (define the-counter (make-web-cell:local 0))


   (define (counter)
     (define request
       (let ((cont-mark  (extract-current-continuation-marks 'key)))
         (eprintf "Continuation Mark ~a / Counter ~a" cont-mark 
(web-cell:local-ref the-counter ))
         (send/suspend
          (lambda (k-url)
            (eprintf "Counter Page k-url ~a" k-url)
            `(html
              (h2 ,(number->string (web-cell:local-ref the-counter )))
              (form ((action ,k-url))
                    (input ((type "submit") (name "add1") (value 
"Add1"))) ; strange behaviour with name "A": it ends up as 'a in bindings
                    (input ((type "submit") (name "E") (value "Exit"))))
              (p ,(string-append "Continuation Mark: " (expr->string 
cont-mark))))))))
     (eprintf "Counter Page After send/suspend")
     (let ((bindings (request-bindings request)))
       (cond
        ((exists-binding? 'add1 bindings)
         (web-cell:local-mask the-counter (add1 (web-cell:local-ref 
the-counter )))
         (counter))
        ((exists-binding? 'E bindings)
         ’exit))))


   (define (main-page)
     (send/suspend
      (lambda (k-url)
        (eprintf "Main Page k-url ~a" k-url)
        `(html (h2 "Main Page")
               (a ((href ,k-url))
                  "View Counter"))))
     (eprintf "Main Page After send/suspend")
     (with-continuation-mark 'key (new-stackkey) (counter))
     (main-page))

   (main-page))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: christoph.schmalhofer.vcf
Type: text/x-vcard
Size: 151 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20061117/257aa1ef/attachment.vcf>

Posted on the users mailing list.