Skip to content

Commit 7c01862

Browse files
committed
feat: add Allman/BSD LISP formatting rules to AI system prompt
Added comprehensive formatting guidelines to teach AI proper code style: ✨ The One-Liner Rule: - Same line close: (define x (+ 1 2)) → Keep inline - Different line close: Opening ( MUST be alone on own line 📚 Documentation Added: - Clear examples of correct vs incorrect formatting - Vertical alignment benefits explained - Indentation rules (2 spaces per level) - Mixed style examples for common patterns 🎯 Why This Matters: - AI-generated LISP is often unreadable one-liners - Vertical alignment makes nesting depth obvious - Easy to spot missing/extra parentheses - Matches conventional LISP formatting (Scheme/Racket style) ✅ Verification: Simple queries already follow the rule naturally: ```lisp (define stats (get_block_stats)) ;; Closes same line ✅ (define slot (. stats currentSlot)) ;; Closes same line ✅ ``` Complex nested code will now use Allman/BSD style when opening and closing parens span multiple lines. 📁 Modified: - src/services/ai_service.rs (system prompt) - Added 67 lines of formatting documentation Related: #code-style #lisp-formatting #readability #ai-generated-code
1 parent 274cedb commit 7c01862

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

src/services/ai_service.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,75 @@ Return status object with cluster health and slot information.
11701170
- Last element: ([] array (- (COUNT array) 1))
11711171
- No negative indexing support
11721172
1173+
**🎨 CODE FORMATTING - ALLMAN/BSD STYLE FOR LISP:**
1174+
1175+
**THE ONE-LINER RULE:**
1176+
- If `(` and `)` close on SAME line → Everything can be inline
1177+
- If `(` and `)` close on DIFFERENT lines → Opening `(` MUST be on its own line
1178+
1179+
**✅ CORRECT Examples:**
1180+
```lisp
1181+
;; One-liner: closes on same line → inline OK
1182+
(define x (+ 1 2))
1183+
1184+
;; Multi-line: opening ( alone on its own line
1185+
(
1186+
define add_tx
1187+
(
1188+
lambda (sender amt sig)
1189+
(
1190+
define idx (FIND senders sender)
1191+
)
1192+
(
1193+
if (== idx -1)
1194+
(
1195+
do
1196+
(set! senders (APPEND senders [sender]))
1197+
(set! amounts (APPEND amounts [amt]))
1198+
)
1199+
(
1200+
do
1201+
(set! amounts (UPDATE amounts idx (+ ([] amounts idx) amt)))
1202+
)
1203+
)
1204+
)
1205+
)
1206+
1207+
;; Mixed style (preferred for readability):
1208+
(
1209+
for (tx page) ;; (tx page) closes same line → inline OK
1210+
(
1211+
when (>= (. tx timestamp) START) ;; condition inline OK
1212+
(
1213+
set! sigs (APPEND sigs [(. tx signature)])
1214+
)
1215+
)
1216+
)
1217+
```
1218+
1219+
**❌ WRONG Examples:**
1220+
```lisp
1221+
;; BAD: ( has "for" on it but doesn't close on same line
1222+
(for (tx page)
1223+
(when condition
1224+
(do-stuff)))
1225+
1226+
;; CORRECT version:
1227+
(
1228+
for (tx page)
1229+
(
1230+
when condition
1231+
(do-stuff)
1232+
)
1233+
)
1234+
```
1235+
1236+
**Formatting Benefits:**
1237+
- Vertical alignment makes nesting depth obvious
1238+
- Easy to spot missing or extra parentheses
1239+
- Consistent indentation = 2 spaces per level
1240+
- Human-readable and machine-parseable
1241+
11731242
**Iteration:**
11741243
- ✅ **LAMBDA FULLY SUPPORTED**: `(lambda (x) (* x 2))` - First-class functions!
11751244
- ✅ **MAP with lambda**: `(map [1 2 3] (lambda (x) (* x 2)))` → `[2, 4, 6]`

0 commit comments

Comments
 (0)