|
1 | 1 | ^{:kindly/hide-code true |
2 | 2 | :clay {:title "The Scittle Repl" |
3 | | - :quarto {:type :post |
| 3 | + :quarto {:author :kloimhardt |
| 4 | + :type :post |
4 | 5 | :date "2025-12-04" |
5 | 6 | :image "appendix_scittlerepl.png" |
6 | 7 | :category :libs |
|
15 | 16 |
|
16 | 17 | ;; ## Starting the Scittle Repl of this Clay Notebook |
17 | 18 |
|
18 | | -;; With this notebook running locally, and seeing this text in the browser window (i.e. notebook is loaded once), uncomment the following line ... |
| 19 | +(defonce start-scittle-nrepl-server |
| 20 | + (memoize |
| 21 | + (fn [start?] |
| 22 | + (println "starting Scittle nrepl server") |
| 23 | + (nrepl/start! {:nrepl-port 1339 :websocket-port 1340})))) |
19 | 24 |
|
20 | | -;; (reset! start-scittle-nrepl-server? true) |
| 25 | +;; To start the nrepl server, in the local .clj file of this very notebook, uncomment the following line ... |
21 | 26 |
|
22 | | -;; ... and reload the notebook. |
| 27 | +;; (start-scittle-nrepl-server true) |
23 | 28 |
|
24 | | -;; Then open an arbitrary (not .clj but) .cljs ClojureScript file. |
| 29 | +;; ... and (re)load this notebook within your local Clay instance. |
25 | 30 |
|
26 | | -;; In your editor, open a repl connection. For example in Emacs/Cider, this means the following 5 steps: (I) *(sesman-start)* (II) choose cider-connect-cljs (III) select localhost (IV) port 1339, followed by (V) the REPL type nbb. |
| 31 | +;; Then open an arbitrary (not .clj but) .cljs ClojureScript file. |
27 | 32 |
|
28 | | -;; Remark: in my setup, to make this work, there must not be another Clojure Repl connection. Because several connections seem to confuse each other, instead of using a Clojure/JVM-Repl, to reload the notebook I start Clay with the file-watcher. With the file-watcher, I make sure that I save any .cljs file before changing this very .clj file of this notebook. An unsaved .cljs file keeps this .clj file from reloading on change. If you keep things tidy, then ... |
| 33 | +;; In your local editor, open a Repl connection. For example in Emacs/Cider, this means the following 5 steps: (I) *(sesman-start)* (II) choose cider-connect-cljs (III) select localhost (IV) port 1339, followed by (V) the REPL type nbb. |
29 | 34 |
|
30 | 35 | ;; Voila, you have a nice Scittle Repl. |
31 | 36 |
|
32 | 37 | ^:kindly/hide-code |
33 | 38 | (kind/hiccup |
34 | 39 | [:img {:src "GClef.svg"}]) |
35 | 40 |
|
| 41 | + |
| 42 | +;; ## The Scittle State |
| 43 | + |
| 44 | +;; The executive summary is that I can only want you to open Clay in file-watcher mode and observe the following |
| 45 | + |
| 46 | +^:kindly/hide-code |
| 47 | +(kind/table |
| 48 | + {"Action" ["Reload browser" "Save this very notebook .clj file" "Save any .cljs file"] |
| 49 | + "Clean Scittle state" ["yes" "yes" "no"]}) |
| 50 | + |
| 51 | + |
| 52 | +;; The Scittle Repl looses its state when the browser window is reloaded. This also means that the Scittle Repl looses its state when this very notebook .clj file is reloaded. As opposed to that, the Clojure/JVM state persists in any case. In fact, this very notebook, in using defonce, relies on a persistent Clojure/JVM state. But the possibility to produce a clean Scittle slate via browser reload can be of great advantage especially for the (domain-expert but) Repl-novice. |
| 53 | + |
| 54 | +;; This notebook works best when Clay is started in file-watcher mode via `clojure -M:clay`. It is not a good idea to open, next to the Scittle Repl, also a Clojure/JVM Repl connection. At least in my setup, opening more than one Repl connection leads to unstable behaviour. Act at your own discretion. |
| 55 | + |
| 56 | +;; With Clay's file watcher active, not only is this very notebook .clj file reloaded on change, but indeed also any Scittle .cljs file that is changed and saved is automatically reloaded. But as opposed to slate-cleaning browser-reload, saving a .cljs file keeps the Scittle state. |
| 57 | + |
| 58 | +;; In sum, while saving a .cljs file keeps the Scittle state, saving this very notebook .clj file cleans the Scittle state. But as I can only want you to happily repl in .cljs files exclusively, further changing and loading of this very notebook is not necessary. Of course, you are free to change and save this very notebook .clj file as often as you like, but make sure all your .cljs files are saved before you do so. Any unsaved Scittle .cljs file keeps this very notebook from reloading on change. |
| 59 | + |
36 | 60 | ;; ## The inner workings of Scittle and sci.nrepl |
37 | 61 |
|
38 | | -;; The following code is just to reveal the inner workings, you should already be happily repling in your .cljs file. |
| 62 | +;; The following code is just to reveal the inner workings, you should already be able to happily repl in your .cljs file. |
39 | 63 |
|
40 | 64 | ;; While this Scittle Repl works perfect with the standard Scittle distribution, scittle-kitchen poses problems with my setup. |
41 | 65 |
|
|
48 | 72 | [:script {:src "https://cdn.jsdelivr.net/npm/scittle@0.6.22/dist/scittle.nrepl.js"}] |
49 | 73 | ]) |
50 | 74 |
|
51 | | -(defonce start-scittle-nrepl-server? (atom false)) |
52 | | - |
53 | | -(defonce active-scittle-nrepl-server? (atom false)) |
54 | | - |
55 | | -(when (and @start-scittle-nrepl-server? |
56 | | - (not @active-scittle-nrepl-server?)) |
57 | | - (reset! active-scittle-nrepl-server? true) |
58 | | - (nrepl/start! {:nrepl-port 1339 :websocket-port 1340}) |
59 | | - :end_when) |
60 | | - |
61 | 75 | ;; ## Also with Babashka |
62 | 76 |
|
63 | | -;; It is possible to start the repl server entirely without Java. |
| 77 | +;; It is possible to start the nrepl server entirely without Java. |
64 | 78 |
|
65 | 79 | ;; Make sure that, in your local directory, there exists the file [browser_server.clj](https://github.com/ClojureCivitas/clojurecivitas.github.io/blob/main/src/mentat_collective/emmy/browser_server.clj) |
66 | 80 |
|
|
70 | 84 | (kind/code |
71 | 85 | "bb -cp . -e \"(require '[browser-server :as nrepl]) (nrepl/start! {:nrepl-port 1339 :websocket-port 1340}) (deref (promise))\"") |
72 | 86 |
|
73 | | -;; For completeness, also the Clojure CLI version |
| 87 | +;; For completeness, I also provide the Clojure CLI version |
74 | 88 |
|
75 | 89 | ^:kindly/hide-code |
76 | 90 | (kind/code |
|
0 commit comments