sci

https://github.com/babashka/SCI - also see #babashka and #nbb
2020-10-14T13:16:05.003100Z

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

borkdude 2020-10-14T13:47:17.003400Z

Nice!

borkdude 2020-10-14T13:49:50.003700Z

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

2020-10-14T13:50:54.004500Z

@borkdude Sure! That'd be nice.

jfntn 2020-10-14T16:20:54.006700Z

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

borkdude 2020-10-14T17:18:32.007400Z

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

jfntn 2020-10-15T14:28:21.020200Z

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

borkdude 2020-10-15T14:33:14.020400Z

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

jfntn 2020-10-15T15:12:15.020600Z

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?

jfntn 2020-10-14T17:24:59.009Z

Those could be resolved on the jvm at least?

borkdude 2020-10-14T17:25:32.009200Z

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

borkdude 2020-10-14T17:25:49.009400Z

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

borkdude 2020-10-14T17:26:27.009600Z

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

jfntn 2020-10-14T17:29:47.011400Z

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

borkdude 2020-10-14T17:39:08.011600Z

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

borkdude 2020-10-14T17:42:38.012900Z

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

borkdude 2020-10-14T19:58:11.013100Z

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

jfntn 2020-10-14T20:02:58.013300Z

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

borkdude 2020-10-14T20:06:04.013600Z

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

borkdude 2020-10-14T20:06:26.013800Z

I assume you're using this lib? https://github.com/redplanetlabs/nippy-serializable-fns

jfntn 2020-10-14T20:06:33.014100Z

yup

borkdude 2020-10-14T20:07:25.014300Z

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

jfntn 2020-10-14T20:10:25.014500Z

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

borkdude 2020-10-14T20:13:17.014700Z

OK, maybe an issue at the redplanets repo then

jfntn 2020-10-14T21:25:21.014900Z

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.

jfntn 2020-10-14T21:26:19.015100Z

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

borkdude 2020-10-14T21:26:48.015300Z

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

jfntn 2020-10-14T21:53:42.015500Z

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)

borkdude 2020-10-14T21:54:35.015700Z

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

borkdude 2020-10-14T21:54:55.015900Z

they are deftypes in impl.vars.cljc

jfntn 2020-10-14T21:55:18.016100Z

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

borkdude 2020-10-14T21:55:53.016300Z

I can imagine implementing this for atom not being so hard

borkdude 2020-10-14T21:56:31.016500Z

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

jfntn 2020-10-14T22:29:23.016700Z

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

jfntn 2020-10-14T22:35:25.016900Z

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