s c h e m a t i c s : c o o k b o o k

/ Cookbook.AToBToC

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Circular Links with Continuations

Problem

You have a number of pages that all link to each other -- this is, the links form a cycle. You want to implement thesse links with continuations.

Solution

Implementing a linear sequence of links is straightforward with continuations. The secret to implementing a cycle of links is to use a variation on the recipe WebDispatchOnLink. Each page is a function from request -> response. Now when we want to create a link to another page we make use of send/suspend/callback as described in WebDispatchOnLink. As all the pages are functions this circular code isn't a problem.

Here is a runnable module with three pages, where each page has links to the other two pages.

(module AToBToC mzscheme
  (require (lib "servlet.ss" "web-server")
           (lib "etc.ss"))

  (provide timeout interface-version start)
  (define timeout 1500)
  (define interface-version 'v1)


  (define callback-a
    (lambda (request)
      (send/suspend/callback
        `(html (head (title "page A"))
               (body (h1 "page A")
                     (p (a ((href ,callback-b)) "to page B"))
                     (p (a ((href ,callback-c)) "to page C")))))))

  (define callback-b
     (lambda (request)
      (send/suspend/callback
        `(html (head (title "page B"))
               (body (h1 "page B")
                     (p (a ((href ,callback-a)) "to page A"))
                     (p (a ((href ,callback-c)) "to page C")))))))

  (define callback-c
    (lambda (request)
      (send/suspend/callback
        `(html (head (title "page C"))
               (body (h1 "page C")
                     (p (a ((href ,callback-b)) "to page B"))
                     (p (a ((href ,callback-a)) "to page A")))))))

  (define start callback-a))

Discussion


Comments about this recipe

I would have liked to attach the full module (so people could download it and run it) but only include fragments of the code in the body of the page.

Next to the Edit link at the top of the page is an Attach link. Use this to attach files -- NoelWelsh

Contributors

ChrisDutchyn wrote the original code.

-- DuckySherwood - 06 Apr 2006

-- NoelWelsh - 07 Apr 2006 Fixed a few things: the ParentTopic should be WebRecipes, made the title a bit more descriptive, hopefully made the text easier to understand.

CookbookForm
TopicType: Recipe
ParentTopic: WebRecipes
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest