Arc Forumnew | comments | leaders | submitlogin
Show Arc: Serializable Closures
4 points by rain1 2135 days ago | 4 comments
Hi!

I wrote a couple of scripts in racket to try out an idea. One is for closure conversion which you can read here [https://gist.github.com/rain-1/36c4851b7c29cf8e42f23ba6eec37be6]

and the second is a small lisp interpreter that builds upon that to implement serializable closures: (https://gist.github.com/rain-1/dc738599829ed40b55f170b574628bd0)

The final 2 test cases demonstrate writing out and reading back a partially applied function.

* There has been discussion about serializing closures recently: (http://arclanguage.org/item?id=20986)



2 points by rain1 2135 days ago | link

I should add: This works because the host lisp is pure: there is no SET! or mutable cells.

If you have mutable cells, write out and read it back in you'd get a clone of the cell - independent of the original. This seems like the wrong behavior.

To make it work with mutable cells seems kind of impossible. I'm not sure. One system I found replaces mutable cells with distributed uniquely identified mailboxes. (termite scheme).

-----

3 points by waterhouse 2117 days ago | link

It's possible to record the fact that some cons cells (or other structures) are identical. The Lisp reader's #n= notation can be used for this, although usually it's only used to print circular lists. Common Lisp's print-circle can be used to demonstrate this:

  * (let ((x (cons 1 2))) (princ (list x x)) nil)
  ((1 . 2) (1 . 2))
  NIL
  * (let ((*print-circle* t)) (let ((x (cons 1 2))) (princ (list x x))) nil)
  (#1=(1 . 2) #1#)
  NIL
Now, if you have a running process, and you want it to seralize a closure (or, generally, an object) that points to a cell that happens to be identical to something else in the process, and you want to read the closure back in and have its pointed-to cell continue to be identical to that other thing... you'll need something more sophisticated. If each object is given some unique id, that would be one approach; that sounds like the mailboxes thing. Another approach would be... say, if the other cell is the 5th element of a list identified with the global name 'blah, then conceivably that could be a good syntax. This might be useful for modules, separate compilation, and/or saving arbitrary process state.

-----

2 points by whitten 2119 days ago | link

Could you elaborate on this or give me pointer what we re it is discussed?

-----

3 points by rain1 2117 days ago | link

what needs explained?

-----