Writing functions and reading them again

I have a data structure that contains Racket functions.
I would like to be able to write it out to a file, and, later, read it in again -- a save-and-restore operation.
But as far as I know, it is impossible to write out a Racket function (yes, it's a closure with its own environment) to an output file in such a way that it can be read in again.

Is this true?
I do want to write something that, when read in, will be the same data structure, containing the same functions whose environments are also part of the read-in data structure.
Just writing out and read-evalling the source code only will not suffice.

I suspect what I want is not available in Racket.

An arbitrary closure is not serializable.

However, you might be able to use


from the web-server.

Yes, web-server/lang/serial-lambda provides serial-lambda and serial-case-lambda forms that create serializable closures. It can be used from #lang racket without any of the other web server infrastructure.

An important caveat is that, for serialization to work, the values closed over by the closure must also be serializable with racket/serialize.