This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-10
Channels
- # announcements (48)
- # asami (8)
- # babashka (186)
- # beginners (56)
- # calva (42)
- # clerk (84)
- # clj-kondo (75)
- # cljdoc (21)
- # clojure (121)
- # clojure-art (1)
- # clojure-australia (1)
- # clojure-china (1)
- # clojure-conj (2)
- # clojure-europe (10)
- # clojure-filipino (1)
- # clojure-hk (1)
- # clojure-indonesia (1)
- # clojure-japan (1)
- # clojure-korea (1)
- # clojure-my (1)
- # clojure-nl (2)
- # clojure-norway (9)
- # clojure-sg (1)
- # clojure-taiwan (1)
- # clojure-uk (2)
- # clojurescript (11)
- # cursive (30)
- # datalevin (20)
- # datomic (4)
- # fulcro (5)
- # gratitude (1)
- # hyperfiddle (89)
- # introduce-yourself (1)
- # java (5)
- # jobs-discuss (8)
- # lsp (89)
- # malli (57)
- # membrane (16)
- # off-topic (12)
- # pathom (38)
- # releases (5)
- # shadow-cljs (17)
- # tools-deps (18)
- # xtdb (62)
I have an issue with caching/state inside clerk/example
. Code snippets and results in the thread.
Having following code:
(def rng1 (java.util.Random. 2288))
^{::clerk/no-cache true}
(clerk/example
(repeatedly 3 #(.nextDouble rng1))
(repeatedly 3 #(.nextDouble rng1))
(do (.setSeed ^java.util.Random rng1 2288) rng1)
(repeatedly 3 #(.nextDouble rng1))) ;; <------ seed is not set!
(def rng2 (java.util.Random. 2288))
^{::clerk/no-cache true}
(repeatedly 3 #(.nextDouble rng2))
^{::clerk/no-cache true}
(repeatedly 3 #(.nextDouble rng2))
^{::clerk/no-cache true}
(do (.setSeed ^java.util.Random rng2 2288) rng2)
^{::clerk/no-cache true}
(repeatedly 3 #(.nextDouble rng2)) ;; <------- seed is set back to 2288
Moreover. With this code (aftere clearing cache):
(def rng1 (java.util.Random. 2288))
^{::clerk/no-cache true}
(clerk/example
(.nextDouble rng1)
(.nextDouble rng1)
(do (.setSeed ^java.util.Random rng1 2288) rng1)
(.nextDouble rng1))
(def rng2 (java.util.Random. 2288))
^{::clerk/no-cache true}
(.nextDouble rng2)
^{::clerk/no-cache true}
(.nextDouble rng2)
^{::clerk/no-cache true}
(do (.setSeed ^java.util.Random rng2 2288) rng2)
^{::clerk/no-cache true}
(.nextDouble rng2)
Everything looks ok, unless I add another
^{::clerk/no-cache true}
(.nextDouble rng2)
somewhere below.@U5H74UNSF can you look at this? thanks!
@U1EP3BZ3Q unlikely I’ll have much time to look into this before next week
well... 🙂 when I apply no-cache
to def
forms as well it works. I don't know why I missed that previously :/
Ok, found it. It affects clerk/exemple
only when sequences are returned: https://github.com/nextjournal/clerk/issues/435
Hi @U1EP3BZ3Q, thanks for the repro. I think this behaviour is not strictly due to a caching issue, but rather something in clerk’s eval phase which forces the top-level lazy-sequences constructed with repeatedly
(Case 2) but not when they’re nested into other collections, like it’s the case for the code emitted by the clerk/example
macro (Case 1).
If in your example, you force your lazy seqs with e.g. a doall
in your first case, you get back the expected behaviour. In Case 3, no lazyness is involved.
That said, if we’d expect lazy seqs to be forced only at display time and not at eval time, then .setSeed
would always be called before calls of .nextDouble
. Is this correct?
I don’t have a clear picture of what’s going on exactly.
I've started to suspect that lazyness could be involved here but didn't check this. Yes, if lazy seqs are evaluated at display time then setSeed is called before generating random numbers.
> if lazy seqs are evaluated at display time and I don’t think this is the case, at this spot https://github.com/nextjournal/clerk/blob/23214a719e191c822901b749bf5f8be867421066/src/nextjournal/clerk/eval.clj#L139 I think we force seqs to check they stay within some limits prior to computing their hash and that’s right after their evaluation
It works like that without clerk/examples
, ie. forms are evaluated in the order they appear (case 2).
I treat clerk/examples
as a nice way to display (kind of) repl session, so the order of evaluation and print should be preserved.
the order is correct in both cases, but the clerk/example
macro wraps single forms in a vector which gets evaluated all at once
Yep, got it, so the only way is to force lazy seqs to be eager. Wrapping into vec
works.
Still, from dumb user perspective there should be no difference between forms wrapped into clerk/example
(or possible other forms) and unwrapped. 🙂 Just the opinion.
> there should be no difference I agree 🙂, the somewhat confusing part is that the unwrapped behaviour is somehow off wrt clojure lazyness
I’ve got either a best practices question or possibly a bug report (I’m using @sritchie09’s clerk-utils)….
I’ve been making files in my notebooks
directory and doing literate programming to write about a problem I’m trying to understand and solve. If an exploration gets lengthy, it seems to make sense to start a new file that builds on previous work. But I think there might be inconsistencies in how namespaces get loaded, and displayed. Observations/example in 🧵
Example: Say I’ve got notebooks/mathpunk/some_problem/day_01.clj. If I start a day_02 file, I can reference that namespace. But if I close the clerk watcher, when I go back and edit day_02, it doesn’t find the namespace, until I go and edit day_01, and then day_02 will be able to find it. Okay so, maybe instead the Right Way is to extract functions for reuse into the src directory. But when I’ve edited something in the src directory, I’m not seeing Clerk automatically show file while I’m editing it.
The issue might be that “notebooks” is not listed in the paths specified in deps.edn
So when you require, day1 isn’t seen on the class path until you manually load it
The watcher issue is probably that you’ve only passed “notebooks” to the watcher in dev/user.clj. You can add “src” to that list if you like!
Apologies if this is my template and it’s been confusing; let me know what we should change here to make the experience better. Adding notebooks to deps.edn seems like a no-brainer here
Interesting… @U5H74UNSF any ideas?
sidenotes, I haven’t gotten the hang of dev
dependencies…. do people use that for their repl utility belts then?
I’m going to try and reproduce what I’m complaining about, lest I encourage you to chase an unmannered goose
When I am developing a library I will have dev dependencies for things like test runners, or maybe something like SCI where I don’t want to force the dependency on someone
This setting controls what directories get watched
Some people don’t like source to get watched since maybe it’s a collection of utilities for example and you don’t want Clerk navigating away from your notebook while you work on that
The paths here should definitely build the class path. https://github.com/mentat-collective/clerk-utils-custom-template/blob/796a0a96cee59f81adb26ce76ff6e808919e3308/deps.edn#L1
Is there a chance that your namespaces don’t match the file path?
That might be it. Is this a Clojure problem too? Like is it just clerk that can’t find notebook 1 from 2, or the repl as well
I guess you wouldn’t know if you’re only using the bb task! That is another guess though, that would break the namespace resolution in require
Should be mathpunk.some-problem.day-01
Dev/user.clj, that’s right
Haha well, the tech should mold to us ideally
But keep notes on what you want the “explore problems with Clerk” experience to feel like, I’m super interested
broadly: • explore in a literate way — writing is as or more important than coding to get me to understand a new thing • reference previous work • extract what’s reusable to a library or “script” file
Hard agree on all! I want a world where maybe 3 isn’t as necessary (the extract part), or at least the extraction brings along a bunch of the writing and exploration
and probably • generate a ✌️site ✌️ or something for people who aren’t running Clojure
That should work from the template already
And I agree it’s critical
yes, I just haven’t gotten there yet. Also we’re on Gitlab rather than Github, there might be differences in the way they do their “Pages”
I want a https://Maria.cloud mode that opens a clerk notebook for live editing / exploration there