► |  | Web Server: PLT HTTP Server

1 | Running the Web Server
2 | Writing Servlets
3 | Extending the Web Server
4 | Troubleshooting and Tips
5 | Acknowledgements
| Index

► | 3 | Extending the Web Server

3.1 | Configuration
3.2 | Setting Up Servlets
3.3 | Dispatchers
3.4 | Web Config Unit
3.5 | Web Server Unit
3.6 | Internal

▼ | 3.6 | Internal

3.6.1 | Timers
3.6.2 | Connection Manager
3.6.3 | Dispatching Server
3.6.4 | Serializable Closures
3.6.5 | Cache Table
3.6.6 | MIME Types
3.6.7 | Serialization Utilities
3.6.8 | URL Param
3.6.9 | Miscellaneous Utilities

► | 3.6.4 | Serializable Closures

3.6.4.1 | Define Closure

On this page:

make-closure-definition-syntax
closure->deserialize-name
3.6.4.1`` Define Closure
define-closure

Version: 4.1.4
top← prev up next →

##### 3.6.4`` Serializable Closures

(require web-server/private/closure)

The defunctionalization process of the Web Language (see Stateless Servlets) requires an explicit representation of closures that is serializable. "private/closure.ss" is this representation. It provides:

(make-closure-definition-syntax |  | tag |  |  |  |
|  | fvars |  |  |  |
|  | proc) |  | → |  | syntax?

tag : syntax?
fvars : (listof identifier?)
proc : syntax?

Outputs a syntax object that defines a serializable structure, with tag as the tag, that represents a closure over fvars, that acts a procedure and when invoked calls proc, which is assumed to be syntax of lambda or case-lambda.

(closure->deserialize-name c) → symbol?
c : closure?

Extracts the unique tag of a closure c.

These are difficult to use directly, so "private/define-closure.ss" defines a helper form:

(require web-server/private/define-closure)

(define-closure tag formals (free-vars ...) body)

Defines a closure, constructed with make-tag that accepts closure that returns freevars ..., that when invoked with formals executes body.

Here is an example:

#lang scheme
(require scheme/serialize)
(define-closure foo (a b) (x y)
(+ (- a b)
(* x y)))
(define f12 (make-foo (lambda () (values 1 2))))
(serialize f12)
'((1) 1 (('page . foo:deserialize-info)) 0 () () (0 1 2))
(f12 6 7)
1
(f12 9 1)
10
(define f45 (make-foo (lambda () (values 4 5))))
(serialize f45)
'((1) 1 (('page . foo:deserialize-info)) 0 () () (0 4 5))
(f45 1 2)
19
(f45 8 8)
20

top← prev up next →