Fork me on GitHub
#sci
<
2020-10-14
>
jeremys13:10:05

@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.

borkdude13:10:50

@jeremys if you want, you can add it to the list here: https://github.com/borkdude/sci#why

jeremys13:10:54

@borkdude Sure! That'd be nice.

jfntn16:10:54

👋 Is it theoretically possible to round-trip an sci context to edn between evaluations with the proper reader extensions?

borkdude17:10:32

@jfntn I don't think so since the context contains reference to values like functions

jfntn17:10:59

Those could be resolved on the jvm at least?

borkdude17:10:32

if these are only core symbols, yes, but it also contains user defined functions

borkdude17:10:49

e.g. if the user does (defn foo []) you don't know what foo is next time

borkdude17:10:27

maybe you can explain your use case and there might be another solution

jfntn17:10:47

I was wondering if it would be possible to pause and resume an evaluation session by just storing and restoring the context

borkdude17:10:08

you could try to store it to an object file, but I'm not sure if that will work :)

borkdude17:10:38

so you could try using nippy. I'm curious how far you would get

borkdude19:10:11

@jfntn Another idea: store the incoming expressions so you can build up the state next time

jfntn20:10:58

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

borkdude20:10:04

Aha. Maybe you can post an issue at that repo's issue

borkdude20:10:25

So what about storing the expressions (events) instead of the state (like CQRS)

jfntn20:10:25

This seems more straightforward, the downsides being you'd have to re-evaluate all expressions every time you want to resume a context

borkdude20:10:17

OK, maybe an issue at the redplanets repo then

jfntn21:10:21

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.

jfntn21:10:19

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

borkdude21:10:48

true, they are closures holding on to the interpreter, since their bodies need interpretation

jfntn21:10:42

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)

borkdude21:10:35

Yep, which might not be that hard, but they are implementation details which could change over time

borkdude21:10:55

they are deftypes in impl.vars.cljc

jfntn21:10:18

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

borkdude21:10:53

I can imagine implementing this for atom not being so hard

borkdude21:10:31

freeze: freeze the deref-ed value, thaw: create new atom with deref-ed value

jfntn22:10:23

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

jfntn22:10:25

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

borkdude06:10:04

Makes sense

jfntn14:10:21

Now I’m wondering what’s really missing to support this, serializable continuations? Not sure it’s possible, have you given this any thoughts?

borkdude14:10:14

since ctx has closures that refer to itself, this may be what's missing for nippy?

jfntn15:10:15

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?