Make evaluation/cache return variables instead of what they point to (for def/defn)#47
Conversation
| (when (and (not no-cache?) (cachable-value? var-value)) | ||
| (cache! digest-file var-value)) | ||
| (let [blob-id (cond no-cache? (view/->hash-str var-value) | ||
| (fn? var-value) nil |
There was a problem hiding this comment.
why do functions get no hash, but other non-cachable things do get hashes?
There was a problem hiding this comment.
because Clojure functions cannot be (de-)serialized.
|
The printing issues should be resolved with dd19391: Dropping the |
3156f27 to
04ca70a
Compare
| wrapped-value (try (wrapped-with-viewer xs viewers) ;; TODO: respect `viewers` on `xs` | ||
| (catch #?(:clj Exception :cljs js/Error) _ex | ||
| nil)) | ||
| (do (println _ex) |
| (let [value (or (get results-last-run hash) | ||
| (thaw-from-cas cas-hash))] | ||
| (when (and introduced-var (not (::var-from-def value))) | ||
| (intern *ns* (-> introduced-var symbol name symbol) value)) |
There was a problem hiding this comment.
the results-last-run for (def x 1) will point to {::var-from-def #'x} and then without the (not (::var-from-def value)) we would (intern *ns* #'x {::var-from-def #'x}) which causes the viewer code to stackoverflow when it it tries to display this var.
I'm unsure what the best approach to caching vars that we want to leave unresolved until viewer time (to allow for test running for example). So I just added a skip here. I think that the cache-to-filesystem code still caches the var->value even if it comes from a def, we just never use it.
c08f6a7 to
15b4795
Compare

We'd like to allow for different ways to run and render tests from within notebooks.
clojure.test'sdeftestdefines a variable with a:testmetadata field present. It would be great to have this at render time, but clerk currently resolves variables returned bydefanddefninto what they point to. The changes here defer this resolution to the viewer so that we can add a viewer that checks for test meta-data and either hides or executes and shows results. We still don't want to resolve normal vars (that are the result of non-def/defn expression evaluation), so I introduced awrapped-varto distinguish between the two.The PR also:
read+eval-cachedread+eval-cachedinto smaller functions. Let me if I went too overboard here; many well-named and small functions helps me with code readability but that might be the case for everyone.open issues to be resolved:
deftestresults in a string result when it should be render a function