Skip to content

Commit 027b7dc

Browse files
committed
Extend the ClojureScript overview page
1 parent d467130 commit 027b7dc

File tree

1 file changed

+76
-4
lines changed

1 file changed

+76
-4
lines changed

doc/modules/ROOT/pages/cljs/overview.adoc

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ available in ClojureScript (yet). For instance, the test runner and
66
debugger are currently Clojure-only features.
77

88
Unlike the Clojure ecosystem that is dominated by a single REPL, the
9-
ClojureScript ecosystem has a number of different choices for REPLs. You'll have
10-
to decide which one you want to run and how you want CIDER to interact
11-
with it.
9+
ClojureScript ecosystem has a number of different choices for REPLs
10+
(e.g. `nashorn`, `node`, `weasel`, `figwheel` and `shadow-cljs`). You'll have to
11+
decide which one you want to run and how you want CIDER to interact with it.
12+
13+
In this section we'll take a look at how ClojureScript support is implemented in CIDER,
14+
and in the subsequent sections we'll discuss how to launch a ClojureScript REPL
15+
and how to setup the most popular ClojureScript REPLs.
1216

1317
== nREPL and ClojureScript
1418

@@ -19,23 +23,91 @@ ClojureScript support.
1923
Piggieback works in the following manner:
2024

2125
* You start a regular Clojure REPL
22-
* You run some Clojure in it that converts to a ClojureScript REPL
26+
* You run some Clojure code in it, that converts it to a ClojureScript REPL
2327

2428
This means that jacking-in is a two-fold process for ClojureScript, compared to Clojure,
2529
as now we have the extra REPL "upgrade" step.
2630

31+
On the bright side - this also means that you can host side by side Clojure and ClojureScript
32+
REPLs in a single nREPL connection! This opens up all sorts of interesting possibilities
33+
that we'll discuss later on.
34+
35+
== Differences with the Standard ClojureScript REPL
36+
37+
While the Piggieback-powered ClojureScript REPLs behave more or less
38+
the same as the standard ClojureScript REPL, there are few subtle
39+
differences everyone has to be aware of.
40+
41+
=== Handling of Multiple Forms
42+
43+
Here's how the standard ClojureScript behaves with multiple input forms:
44+
45+
cljs.user>
46+
(declare is-odd?)
47+
(defn is-even? [n] (if (= n 0) true (is-odd? (dec n))))
48+
(defn is-odd? [n] (if (= n 0) false (is-even? (dec n))))
49+
#'cljs.user/is-odd?
50+
#'cljs.user/is-even?
51+
#'cljs.user/is-odd?
52+
cljs.user> (is-even? 4)
53+
true
54+
55+
56+
And here's how a Piggieback-powerd REPL behaves:
57+
58+
cljs.user>
59+
(declare is-odd?)
60+
(defn is-even? [n] (if (= n 0) true (is-odd? (dec n))))
61+
(defn is-odd? [n] (if (= n 0) false (is-even? (dec n))))
62+
#'cljs.user/is-odd?
63+
cljs.user> (is-even? 4)
64+
Compile Warning <cljs repl> line:1 column:2
65+
66+
Use of undeclared Var cljs.user/is-even?
67+
68+
1 (is-even? 4)
69+
^---
70+
71+
#object[TypeError TypeError: Cannot read property 'call' of undefined]
72+
(<NO_SOURCE_FILE>)
73+
cljs.user>
74+
75+
This difference comes from a performance optimization in Piggieback, which avoids
76+
creating an different REPLs for each ClojureScript form it evaluates.
77+
78+
TIP: You can learn more about this difference https://github.com/nrepl/piggieback/pull/98[here].
79+
2780
== Dealing with Dependencies
2881

2982
CIDER doesn't handle automatically ClojureScript REPL dependencies when you're doing
3083
`cider-jack-in-clojurescript`. You'll have to configure those manually yourselves
3184
as documented in the subsequent sections of this manual.
3285

86+
Actually, CIDER will handle automatically the most important dependency - namely Piggieback.
87+
The problem with the other dependencies, however, is that you might need to install
88+
some external tools (e.g. `node`, `shadow-cljs`) and that ClojureScript development
89+
tools like Figwheel and shadow-cljs also require some setup to be useful.
90+
91+
CIDER will try to help you identify missing requirements by running a check, right before
92+
attempting to upgrade a Clojure REPL to a ClojureScript REPL. The nature of this check
93+
differs for the different REPL types:
94+
95+
* For a `node` REPL we check whether the `node` binary is on your `exec-path` (Emacs's version of `PATH`)
96+
* For tools like `figwheel` we check whether they are available on the classpath (by trying to require
97+
some of their namespaces)
98+
99+
We'll discuss those checks further in the upcoming sections.
100+
33101
== Limitations
34102

35103
CIDER currently doesn't support self-hosted ClojureScript implementations (e.g. Lumo).
36104
The reason for this is that there's no self-hosted version of nREPL (implemented in ClojureScript)
37105
available today.
38106

107+
Another unsupported REPL is Rhino. Supporting in it Piggieback required a lot of ugly hacks
108+
and eventually it was decided we were better off without Rhino. Given the abundance
109+
of better solutions today, I doubt anyone's going to miss Rhino anyways.
110+
39111
Additionally, as noted earlier on this page - many of CIDER's advanced features are
40112
currently not available for ClojureScript.
41113

0 commit comments

Comments
 (0)