Skip to content

Commit ccee5c4

Browse files
authored
Tweak Clojure instructions about missing repl (#283)
* Tweak Clojure instructions about missing repl * typos * Tidy up
1 parent 897d61b commit ccee5c4

File tree

1 file changed

+61
-21
lines changed

1 file changed

+61
-21
lines changed

instructions/clojure.instructions.md

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ applyTo: '**/*.{clj,cljs,cljc,bb,edn.mdx?}'
77

88
## Code Evaluation Tool usage
99

10-
“Use the repl” means to use the **Evaluate Clojure Code** tool from Calva Backseat Driver. It connects you to the the same REPL as the user is connected to via Calva.
10+
“Use the repl” means to use the **Evaluate Clojure Code** tool from Calva Backseat Driver. It connects you to the same REPL as the user is connected to via Calva.
1111

1212
- Always stay inside Calva's REPL instead of launching a second one from the terminal.
1313
- If there is no REPL connection, ask the user to connect the REPL instead of trying to start and connect it yourself.
@@ -36,12 +36,67 @@ Docstrings belong immediately after the function name and before the argument ve
3636

3737
- Define functions before they are used—prefer ordering over `declare` except when truly necessary.
3838

39+
## Interactive Programming (a.k.a. REPL Driven Development)
40+
41+
### Align Data Structure Elements for Bracket Balancing
42+
**Always align multi-line elements vertically in all data structures: vectors, maps, lists, sets, all code (since Clojure code is data). Misalignment causes the bracket balancer to close brackets incorrectly, creating invalid forms.**
43+
44+
```clojure
45+
;; ❌ Wrong - misaligned vector elements
46+
(select-keys m [:key-a
47+
:key-b
48+
:key-c]) ; Misalignment → incorrect ] placement
49+
50+
;; ✅ Correct - aligned vector elements
51+
(select-keys m [:key-a
52+
:key-b
53+
:key-c]) ; Proper alignment → correct ] placement
54+
55+
;; ❌ Wrong - misaligned map entries
56+
{:name "Alice"
57+
:age 30
58+
:city "Oslo"} ; Misalignment → incorrect } placement
59+
60+
;; ✅ Correct - aligned map entries
61+
{:name "Alice"
62+
:age 30
63+
:city "Oslo"} ; Proper alignment → correct } placement
64+
```
65+
66+
**Critical**: The bracket balancer relies on consistent indentation to determine structure.
67+
68+
### REPL Dependency Management
69+
Use `clojure.repl.deps/add-libs` for dynamic dependency loading during REPL sessions.
70+
71+
```clojure
72+
(require '[clojure.repl.deps :refer [add-libs]])
73+
(add-libs '{dk.ative/docjure {:mvn/version "1.15.0"}})
74+
```
75+
76+
- Dynamic dependency loading requires Clojure 1.12 or later
77+
- Perfect for library exploration and prototyping
78+
79+
### Checking Clojure Version
80+
81+
```clojure
82+
*clojure-version*
83+
;; => {:major 1, :minor 12, :incremental 1, :qualifier nil}
84+
```
85+
86+
### REPL Availability Discipline
87+
88+
**Never edit code files when the REPL is unavailable.** When REPL evaluation returns errors indicating that the REPL is unavailable, stop immediately and inform the user. Let the user restore REPL before continuing.
89+
90+
#### Why This Matters
91+
- **Interactive Programming requires a working REPL** - You cannot verify behavior without evaluation
92+
- **Guessing creates bugs** - Code changes without testing introduce errors
93+
3994
## Structural Editing and REPL-First Habit
4095
- Develop changes in the REPL before touching files.
4196
- When editing Clojure files, always use structural editing tools such as **Insert Top Level Form**, **Replace Top Level Form**, **Create Clojure File**, and **Append Code**, and always read their instructions first.
4297

4398
### Creating New Files
44-
- Use the **Create Clojure File** tool, with initial content
99+
- Use the **Create Clojure File** tool with initial content
45100
- Follow Clojure naming rules: namespaces in kebab-case, file paths in matching snake_case (e.g., `my.project.ns``my/project/ns.clj`).
46101

47102
### Reloading Namespaces
@@ -51,22 +106,6 @@ After editing files, reload the edited namespace in the REPL so updated definiti
51106
(require 'my.namespace :reload)
52107
```
53108

54-
### Keeping Brackets Balanced
55-
If tools or the compiler signal bracket imbalance, stop and ask for help rather than guessing—use the human-input tool.
56-
57-
## Interactive Programming with REPL
58-
59-
When evaluating code during development, always show the complete code being evaluated in a code block before using evaluation tools. The code block should start with the appropriate `(in-ns ...)` form and contain the exact code being evaluated, so the human can run the same code in their REPL.
60-
61-
Example:
62-
```clojure
63-
(in-ns 'my.namespace)
64-
(let [test-data {:name "example"}]
65-
(process-data test-data))
66-
```
67-
68-
This applies to all REPL-driven development, whether using Calva, Joyride, or other Clojure evaluation tools.
69-
70109
## Code Indentation Before Evaluation
71110
Consistent indentation is crucial to help the bracket balancer.
72111

@@ -121,7 +160,7 @@ You can also use "inline def" when showing the user code in the chat, to make it
121160

122161
## Return values > print side effects
123162

124-
Prefer using the repl and return values from your evaluations, over printing things to stdout.
163+
Prefer using the REPL and return values from your evaluations, over printing things to stdout.
125164

126165
## Reading from `stdin`
127166
- When Clojure code uses `(read-line)`, it will prompt the user through VS Code.
@@ -272,9 +311,9 @@ Iterate with real data before editing files.
272311
```
273312

274313
#### Benefits
275-
- Verified behaviour before committing changes
314+
- Verified behavior before committing changes
276315
- Incremental development with immediate feedback
277-
- Tests that capture known-good behaviour
316+
- Tests that capture known-good behavior
278317
- Start new work with failing tests to lock in intent
279318

280319
### Test Naming and Messaging
@@ -307,3 +346,4 @@ Guidelines:
307346
## Happy Interactive Programming
308347

309348
Remember to prefer the REPL in your work. Keep in mind that the user does not see what you evaluate. Nor the results. Communicate with the user in the chat about what you evaluate and what you get back.
349+

0 commit comments

Comments
 (0)