5.3 Serializable Closures
The defunctionalization process of the Web Language (see Stateless Servlets) requires an explicit representation of closures that is serializable.
(serial-lambda formals body ...)
(serial-case-lambda [formals body ...] ...)
(define-closure tag formals (free-var ...) body)
Defines a closure, constructed with make-tag that accepts a closure that returns
freevar ..., that when invoked with formals
executes body.
Here is an example:
#lang racket (require racket/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