The answer to the "WHY" is this:
1. send/form2 is generalized over 'f', so the particular binding for
'f' must be part of its closure, which must be serialized.
2. If you inline it, or replace the f is send/form2 with
'main-input-formlet', then you are now referring to a global variable,
which is never part of closures, because it is always available.
3. The value that you are giving to 'main-input-formlet' is not
serializable, because it is a normal function. This is documented on
the contract for formlets:
Now, the question you didn't ask, does it have to be this way? (1) and
(2) have to work the way that they do. (3) is a little bit harder to
decide if it has to be that way. Serializability is an infectious
property where you can't just rely on your local code to do something,
but you need global changes across the system. The Web server does not
generally promise that its data structures are serializable (for
example, requests are not because they contain promises, which would
be very expensive to make serializable across the system.) The only
"easy" way to make formlets serializable would be to write that file
in the "#lang web-server" language. But down that path is writing
every module in Racket in this language. (For example, objects and
classes aren't generally serializable so the second you start using
them in a Web app you want to be serializable, you're in for a world
of hurt.)
I don't think the benefits are worth it to justify things in the case
of formlets, but I'm open to arguments.
What should you do instead in this and similar situations? This is the
reason for serial->native, etc. You could also change your program so
that the set of valid formlets were always top-level, if that were the
case, and name them by symbol.
Jay
--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay
"The glory of God is Intelligence" - D&C 93
Yes... you would want to use call-with-web-prompt from
https://github.com/plt/racket/blob/master/collects/web-server/lang/abort-resume.rkt
And it should "just work"
> Another way is to modify make-servlet-tester to not redact the response so I can test other properties like return code and headers. But I'd prefer to do it directly.
I think this would be better to do. We just need to change line 24
https://github.com/plt/racket/blob/master/collects/web-server/test.rkt#L24
to support the stateless mode.
And lines 53-57 to allow you to see the currently un-named part of the
bytes (the .+ in the regexp.)
Jay
--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay
"The glory of God is Intelligence" - D&C 93
____________________
Jay