Advertisement
Shinmera

Radiance Request Continuations Example

Oct 24th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.92 KB | None | 0 0
  1. ;; Theoretical application for request continuations.
  2.  
  3. (defmacro branch (text &body branches)
  4.   (let ((contsym (gensym "CONTINUATION"))
  5.         (rqvarsym (gensym "REQUEST")))
  6.     `(let ((,contsym (with-request-continuation (:new-request-var ,rqvarsym)
  7.                        (string-case ((get-var "choice" ,rqvarsym))
  8.                          ,@branches))))
  9.        "<generated form with choices and text, too lazy to code it out here.>")))
  10.  
  11. (defpage #p"adventure./" ()
  12.   (branch "You are standing on a green field."
  13.     ("Go left"
  14.      (branch "You enter a dark forest."
  15.        ("Go further" "A wolf eats your face.")
  16.        ("Wait" "A wolf eats your face.")))
  17.     ("Go right"
  18.      (branch "You enter a bright city."
  19.        ("Enter a bar" "You are killed by a hooker.")
  20.        ("Enter a casino" "You are killed by a hooker.")
  21.        ("Leave" "You are killed by a hooker.")))
  22.     ("Wait" "Birds peck your brains out.")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement