Version: 4.2
5.3 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. This module provides that representation.
| |||||||||||||||||||||
| 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 we provide a helper syntactic 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 |