@borkdude Hi, I have finally released https://github.com/JeremS/prose. The eval-form
function going in the main API helped a lot. Thanks again for helping with my questions.
Nice!
@jeremys if you want, you can add it to the list here: https://github.com/borkdude/sci#why
@borkdude Sure! That'd be nice.
👋 Is it theoretically possible to round-trip an sci context to edn between evaluations with the proper reader extensions?
@jfntn I don't think so since the context contains reference to values like functions
Now I’m wondering what’s really missing to support this, serializable continuations? Not sure it’s possible, have you given this any thoughts?
since ctx has closures that refer to itself, this may be what's missing for nippy?
Sorry, I meant I'm not sure the ctx is serializable due to the circular reference. Do you think that's solvable outside of sci?
Those could be resolved on the jvm at least?
if these are only core symbols, yes, but it also contains user defined functions
e.g. if the user does (defn foo [])
you don't know what foo is next time
maybe you can explain your use case and there might be another solution
I was wondering if it would be possible to pause and resume an evaluation session by just storing and restoring the context
you could try to store it to an object file, but I'm not sure if that will work :)
https://tech.redplanetlabs.com/2020/01/06/serializing-and-deserializing-clojure-fns-with-nippy/
so you could try using nippy. I'm curious how far you would get
@jfntn Another idea: store the incoming expressions so you can build up the state next time
Nippy seems to be having a hard time with the run-fn
returned by sci.impl.fns/parse-fn-args+body
(-> sci-ctx :env deref :namespaces (get 'user) (get 'foo) )
;; => #<SciVar@2fa20b2d: #function[sci.impl.fns/parse-fn-args+body/run-fn--25249]>
(-> sci-ctx :env deref :namespaces (get 'user) (get 'foo) nippy/freeze)
Execution error (NoSuchFieldException) at java.lang.Class/getField (Class.java:2013).
meta
Aha. Maybe you can post an issue at that repo's issue
I assume you're using this lib? https://github.com/redplanetlabs/nippy-serializable-fns
yup
So what about storing the expressions (events) instead of the state (like CQRS)
This seems more straightforward, the downsides being you'd have to re-evaluate all expressions every time you want to resume a context
OK, maybe an issue at the redplanets repo then
Wondering if this is the right approach though... sci.impl.fns/parse-fn-args+body
will return fns that call back into sci's eval, so we'd need to close over a big chunk of the whole interpreter for every function in the env.
Realized this was the case while digging into the nippy exception, which seems to happen when trying to serialize the eval-do*
that was passed to parse-fn-args+body
true, they are closures holding on to the interpreter, since their bodies need interpretation
Right so I think the issue here is that I need to extend nippy's freeze and thaw for all the sci datatypes (Var, Namespace etc)
Yep, which might not be that hard, but they are implementation details which could change over time
they are deftypes in impl.vars.cljc
Actually it's not just sci, also requires supporting freeze/thaw for e.g. clojure.lang.Atom since it's part of the env being closed over
I can imagine implementing this for atom not being so hard
freeze: freeze the deref-ed value, thaw: create new atom with deref-ed value
Right, but the custom data types are inside the atom so it makes for a confusing mix of print-method and freeze/thaw extensions, can probably figure this out though
Trying to freeze the ctx now and getting a stack overflow on the first SciVar for a fn, actually not sure this is workable since there's a circular dependency between the ctx and the functions that closer over it