News for hackers. Stuff that matters.
Re:Seaside – Developing Sophisticated Web Applications in Sm... by dang on Saturday March 05, 2016 @01:25PM (#11230336)
That's interesting; I didn't know that any language did that.

I really like your design idea, and it would be fun to think of an application for which it was the best fit.

Re:Seaside – Developing Sophisticated Web Applications in Sm... by derefr on Saturday March 05, 2016 @02:02PM (#11230524)
Even Erlang's approach is sort of a hack. As can be seen from the format spec, Erlang doesn't actually encode the AST of the closure; instead, they ship a reference to a symbol-table ref in a module. Erlang's closures are all implicitly hoisted out into their own gensym'ed functions and then exported from their module to allow for this. Each node assumes the other nodes in the same distributed system all have access to the same modules (not that they all necessarily have it loaded, but that they can load it Just-In-Time when dereferencing the closure) and so the export-table reference can be turned back into a handle on the closure at the receiving end by looking it up in its module.

What this all means is that, although Erlang nodes can rehydrate closures from other nodes that are running the same code, they can't rehydrate arbitrary closures defined and serialized at your personal REPL running different code. (Which defeats half the purpose; you can't then use dehydrated closures as an arbitrary query/callback/RPC syntax between Erlang-based microservices, unless they all share code.)

On the other hand, there's nothing explicitly stopping the Erlang Run Time System from supporting the full version, where a closure is dehydrated as its AST (plus free vars, as in ETF encoding.) And so this is exactly what Elixir does. Yet another reason Elixir is an interesting language.

Re:Seaside – Developing Sophisticated Web Applications in Sm... by dang on Saturday March 05, 2016 @06:34PM (#11231633)
So what's encoded are the closed variables along with the gensym'ed name of the closure (effectively a pointer to the code)? If so, that's pretty useful. For some cases it's better than serializing the code, because then you don't have to pass a copy of the code around everywhere, only the state that you don't keep a copy of.