Lave: eval in reverse
github.com
github.com
It looks very interesting to me from the point of view of dealing with certain data types better (at all, in fact), and handling circular references.
I think it's one of those "easy on the surface, but surprisingly complex" problems.
When you start allowing arbitrary code execution, it's a lot of work to prevent certain "functions" (i mean that in the non-programming way).
Trying to detect the unsafe parts so they could be turned off after that point would be impossible as you suspect (the task would be constrained by the halting problem, https://en.wikipedia.org/wiki/Halting_problem).
This is why, for instance, there's no native Date format in JSON. Dates in JavaScript require running a constructor -- new Date() -- so they aren't in JSON.
And by ring, I of course mean HMAC.
(edited to add that, of course, pickle is part of the python standard library, which makes this specific feature less interesting)
In case it is useful: https://gist.github.com/bprosnitz/cf1d1a3dd1008eef5a85
The down-side is that a consumer has to run a full-blown eval() (as opposed to the more restricted JSON.parse()). This isn't that much of a downside in a typical webapp since you have full control over the browser process anyway, but it's deadly for cross-domain.
The upside is considerable for certain data-structures that are hard to represent in JSON efficiently, e.g. with a lot of denormalization.
A key concern for me is runtime efficiency, particularly compared to JSON.stringify.
As far as efficiency, I'd think for most uses the issue would be on the JSON.parse end. In this case, lave might be more efficient, since JSON reviving often ends up creating temporary objects that need to GC'ed after reification.
Also, it would be interesting to support other data-types, such as the ones that come with Immutable.js. That would be slick.
What would be fantastic for perl is actually something that javascript already has. In most browsers, if you print a data structure to the console, it is presented as a clickable tree structure, where you can show or hide the bits of the data that you want to check.
I'd love some way to recreate this in perl (and in a terminal if possible). The downside of Data::Dumper is that you can produce hundreds of pages of output, when you really want to just examine a tiny part of it.
AFAIK, no one has written a terminal version yet. There's a TUI framework called Tickit which would make writing one quite easy, I think.
https://github.com/dclowd9901/betterObjectToString
Yours is clearly better.
If code-to-be-evaluated represents data, you have to trust it or else very carefully sandbox it.
The real fix is to have a printed notation that has a richer type system and handles circularity.
(Printed notation is code, effectively; it's just code in a distinct language of hopefully limited power, just for constructing objects from a description.)
For custom classes you have to define custom printing methods, because, well, how you print a particular object readably has no general answer: for example, for some data (streams, threads), it makes no sense to serialize them. Java has the "transient" keyword to avoid serializing some fields in classes. You should also set PRINT-READABLY to T so that you have an error if an object cannot be printed readably.
Also, Common Lisp has to serialize values into FASL files when compiling them, but it can do it only for its own types. You can use LOAD-TIME-VALUE to have a form evaluated at load time, and MAKE-LOAD-FORM is a generic function that you can specialize to print a form which, when read, allocates and initializes objects at load-time. For your own classes, it is sufficient to use the helper function MAKE-LOAD-FORM-SAVING-SLOTS.
All that gives you a lot of control over what, how and when forms are evaluated and stored. The good news is that you have libraries available to do that very easily: http://www.cliki.net/serialization (see for example http://www.cliki.net/cl-marshal).
It's good that I am washing myself = Es bueno que me esté lavando.
(That's a literal translation: I don't think anyone would use "lavar" for washing yourself, more likely "bañando" [bathing] or "aseando" [cleaning] --at least not in Mexico, but what's idiomatic does vary quite a bit from country to country. Although for "wash your face" you would say "lávate la cara", using the verb "lavar".)
I am washing it = Lo estoy lavando.
Here are some sentences where I would use "lave" or "lavé":
Dile que lo lave mañana= Tell him/her to wash it tomorrow
Lavé las cortinas con agua caliente = I washed the curtains in hot water.
It also means "to wash" in English.