- src/jolt/clojure/string.clj (123 lines, 20 functions): blank?, capitalize, lower-case, upper-case, includes?, join, replace, replace-first, str-reverse, split, starts-with?, ends-with?, trim, triml, trimr, trim-newline, escape, index-of, last-index-of - src/jolt/clojure/set.clj (124 lines, 10 operations): union, intersection, difference, select, project, rename, rename-keys, map-invert, join, index, subset?, superset? - src/jolt/clojure/walk.clj (77 lines, 9 functions): walk, postwalk, prewalk, postwalk-demo, prewalk-demo, postwalk-replace, prewalk-replace, keywordize-keys, stringify-keys, macroexpand-all - src/jolt/core.janet: 11 Janet string interop bindings (str-trim, str-upper, str-lower, str-find, str-replace, str-replace-all, str-reverse-b, str-join, str-split, str-triml, str-trimr) - test/phase10-test.janet: 2 test sections (40-41) 15+ assertions covering string and set functions - All .clj files use eval-form for multi-form loading - 315 ok, 2 fail (pre-existing, unchanged)
68 lines
No EOL
2.4 KiB
Markdown
68 lines
No EOL
2.4 KiB
Markdown
---
|
|
name: jolt-gotchas
|
|
description: Common pitfalls and workarounds discovered during Jolt implementation
|
|
---
|
|
|
|
# jolt-gotchas
|
|
|
|
Recurring pitfalls and their fixes discovered across all implementation phases.
|
|
|
|
## PHM/Set Metadata Key Leakage
|
|
|
|
PHM and set internal keys (`:jolt/deftype`, `:cnt`, `:buckets`, `:_meta`, `:jolt/type`, `:phm`) leak into `pairs`/`keys` iteration. Must filter in merge, merge-with, keys, vals, and print-collection.
|
|
|
|
```janet
|
|
(when (and (not= k :jolt/deftype) (not= k :cnt)
|
|
(not= k :buckets) (not= k :_meta)
|
|
(not= k :jolt/type) (not= k :phm)) ...)
|
|
```
|
|
|
|
## Keywords with `#` Are Invalid Janet Literals
|
|
|
|
`:#inst`, `:#uuid` cause parse errors. Use dynamic table construction:
|
|
```janet
|
|
(let [dr @{}] (put dr (keyword "#inst") fn) dr)
|
|
```
|
|
|
|
## Janet `break` Only Works in Loops
|
|
|
|
Does NOT work inside `let`. Use `(var found nil)` + `(set found val) (break)` pattern.
|
|
|
|
## Bare Tuples in `eval` Are Function Calls
|
|
|
|
`(eval [1 2 3])` calls `1` as function. Use `['tuple 1 2 3]` in data-structure emitter.
|
|
|
|
## Janet `case` for Multi-Arity
|
|
|
|
Janet lacks Clojure-style multi-arity defn. Use `(defn f [& args] (case (length args) 1 ... 2 ...))`.
|
|
|
|
## core-renames + core-fn-values Must Stay in Sync
|
|
|
|
Both tables must be updated together when adding core fns. Missing entries = silent nil returns. `"-"` is `core-sub` NOT `core--`.
|
|
|
|
## `set!` Field Mutation Reader Quirk
|
|
|
|
`(set! (.-x obj) val)` parses as array with `.-x` symbol head — not as standalone `.-x` symbol. Check for this case before the `(. obj -field)` shorthand.
|
|
|
|
## Janet `cond` Requires `true` Guard for Catch-All
|
|
|
|
A bare expression in the last position of `cond` is treated as a **test** clause (not body). Use `true` as the test:
|
|
|
|
```janet
|
|
(cond (nil? x) (buf "nil") (number? x) (buf (string x)) true (buf (string x)))
|
|
```
|
|
|
|
Without `true`, the last expression executes as a side-effect test between branches. Hit us in buffer-based write-value — raw tuple addresses leaked into REPL output.
|
|
|
|
## Janet `cond` Requires `true` Guard for Catch-All
|
|
|
|
A bare expression in the last position of `cond` is treated as a **test** clause (not body). It executes between other branches as a side-effect test. Use `true` as the test to make it a proper catch-all:
|
|
|
|
```janet
|
|
(cond
|
|
(nil? x) (buf "nil")
|
|
(number? x) (buf (string x))
|
|
true (buf (string x))) ; ← `true` required
|
|
```
|
|
|
|
Without `true`, `(push-str buf (string v))` in the last position leaked raw tuple addresses into REPL output. |