Skip to content

Commit 82dcf1d

Browse files
authored
The Scittle Repl (#213)
* one * two
1 parent f5bb47b commit 82dcf1d

File tree

3 files changed

+60
-14
lines changed

3 files changed

+60
-14
lines changed

deps.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
org.soulspace/qclojure {:mvn/version "0.22.0"}
6161
org.babashka/http-client {:mvn/version "0.4.22"}
62+
io.github.babashka/sci.nrepl {:mvn/version "0.0.2"}
6263
com.github.danielsz/bioscoop {:mvn/version "1.0.5"}
6364
yamlscript/core {:git/url "https://github.com/yaml/yamlscript"
6465
:git/sha "ed7adfbf90a39f379d5a7193bb2e4bdd7f0eecf8"
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
11
^{:kindly/hide-code true
2-
:clay {:title "scittle repl"
3-
:quarto {:type :draft
4-
;; :sidebar "emmy-fdg"
2+
:clay {:title "The Scittle Repl"
3+
:quarto {:type :post
54
:date "2025-12-04"
5+
:image "GClef.svg"
66
:category :libs
7-
:tags [:emmy :physics]}}}
7+
:tags [:scittle :repl]}}}
88
(ns mentat-collective.emmy.appendix-scittlerepl
9-
(:refer-clojure :exclude [+ - * / zero? compare divide numerator
10-
denominator
11-
time infinite? abs ref partial =])
12-
(:require [scicloj.kindly.v4.api :as kindly]
13-
[scicloj.kindly.v4.kind :as kind]))
9+
(:require
10+
[sci.nrepl.browser-server :as nrepl]
11+
[scicloj.kindly.v4.api :as kindly]
12+
[scicloj.kindly.v4.kind :as kind]))
13+
14+
;; ## Starting the Scittle Repl of this Clay Notebook
15+
16+
;; With this notebook running locally, and seeing this text in the browser window (i.e. notebook is loaded once), uncomment the following line ...
17+
18+
;; (reset! start-scittle-nrepl-server? true)
19+
20+
;; ... and reload the notebook.
21+
22+
;; Then open an arbitrary (not .clj but) .cljs ClojureScript file.
23+
24+
;; 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.
25+
26+
;; 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 ...
27+
28+
;; Voila, you have a nice Scittle Repl.
1429

1530
^:kindly/hide-code
31+
(kind/hiccup
32+
[:img {:src "GClef.svg"}])
33+
34+
;; ## The inner workings of Scittle and sci.nrepl
35+
36+
;; The following code is just to reveal the inner workings, you should already be happily repling in your .cljs file.
37+
38+
;; While this Scittle Repl works perfect with the standard Scittle distribution, scittle-kitchen poses problems with my setup.
39+
1640
(kind/hiccup
1741
[:div
1842
[:script "var SCITTLE_NREPL_WEBSOCKET_PORT = 1340"]
@@ -22,14 +46,30 @@
2246
[:script {:src "https://cdn.jsdelivr.net/npm/scittle@0.6.22/dist/scittle.nrepl.js"}]
2347
])
2448

25-
;; make sure that, in your local directory, there exists the file [browser_server](https://clojurecivitas.github.io/mentat_collective/emmy/browser_server.html)
49+
(defonce start-scittle-nrepl-server? (atom false))
50+
51+
(defonce active-scittle-nrepl-server? (atom false))
52+
53+
(when (and @start-scittle-nrepl-server?
54+
(not @active-scittle-nrepl-server?))
55+
(reset! active-scittle-nrepl-server? true)
56+
(nrepl/start! {:nrepl-port 1339 :websocket-port 1340})
57+
:end_when)
58+
59+
;; ## Also with Babashka
60+
61+
;; It is possible to start the repl server entirely without Java.
62+
63+
;; 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)
64+
65+
;; Then in the terminal, start babashka in the following way
2666

27-
;; Then in the terminal start babashka in the following way
2867
^:kindly/hide-code
2968
(kind/code
3069
"bb -cp . -e \"(require '[browser-server :as nrepl]) (nrepl/start! {:nrepl-port 1339 :websocket-port 1340}) (deref (promise))\"")
3170

71+
;; For completeness, also the Clojure CLI version
3272

33-
;; then open a (not .clj but) .cljs file in your editor
34-
35-
;; In Cider, choose cider-connect-cljs, select localhost, port 1339, followed by the REPL type nbb .
73+
^:kindly/hide-code
74+
(kind/code
75+
"clj -Sdeps \"{:deps {io.github.babashka/sci.nrepl {:mvn/version \\\"0.0.2\\\"}}}\" -M -e \"(require '[sci.nrepl.browser-server :as nrepl]) (nrepl/start! {:nrepl-port 1339 :websocket-port 1340})\"")

0 commit comments

Comments
 (0)