[Ruby] marshalling lambdas
Phil Hagelberg
phil at hagelb.org
Fri Aug 22 13:51:04 PDT 2008
"Joe Van Dyk" <joe at pinkpucker.net> writes:
> In Ruby, I guess you can't marshal a lambda/proc object, right? Is
> that possible in lisp or other languages?
You can't do it reliably in any language as far as I know since you
would have to save the environment as well so you would still have
access to any free variables it uses.
Here's a post about it with the caveat that it won't work if you care
about closures. It's basically suggesting just storing them as strings
and evaling them when needed, which is hacky but whatever:
http://gilesbowkett.blogspot.com/2008/08/storing-procs-in-database.html
You could probably do better with ruby2ruby though; I'm not that
familiar with the lib. But yeah, serializing code is built-in to lisp.
Here's how to do it in Bus Scheme:
> (send (lambda () (+ 2 2)) 'inspect)
-Phil
More information about the Ruby
mailing list