From 9813186ef9bc04623990697db5ce4cef2b670b5c Mon Sep 17 00:00:00 2001 From: Yogthos Date: Sat, 13 Jun 2026 15:41:59 -0400 Subject: [PATCH] fix: def supports the 3-arg docstring form (def name doc value) in compile mode (jolt-6ym) The analyzer always took (nth items 2) as the value, so (def x "doc" 42) bound x to the docstring and dropped 42. Now it mirrors the interpreter: when there are 4+ items and item 2 is a string, item 2 is the docstring (attached as :doc meta) and item 3 is the value. Conformance 335/335 x3. --- jolt-core/jolt/analyzer.clj | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/jolt-core/jolt/analyzer.clj b/jolt-core/jolt/analyzer.clj index 8840292..7c0f37d 100644 --- a/jolt-core/jolt/analyzer.clj +++ b/jolt-core/jolt/analyzer.clj @@ -159,9 +159,16 @@ (when (< (count items) 3) (uncompilable "def with no init")) (let [nm (form-sym-name name-sym) - cur (compile-ns ctx)] + cur (compile-ns ctx) + ;; (def name docstring value): docstring is form 2, value form 3. + ;; Matches the interpreter; without this the docstring was taken + ;; as the value and the real init dropped (jolt-6ym). + has-doc (and (> (count items) 3) (string? (nth items 2))) + val-form (nth items (if has-doc 3 2)) + base-meta (or (form-sym-meta name-sym) {}) + node-meta (if has-doc (assoc base-meta :doc (nth items 2)) base-meta)] (host-intern! ctx cur nm) - (def-node cur nm (analyze ctx (nth items 2) env) (form-sym-meta name-sym)))) + (def-node cur nm (analyze ctx val-form env) node-meta))) "let*" (let [bvec (vec (form-vec-items (nth items 1))) r (analyze-bindings ctx bvec env)] (let-node (first r) (analyze-seq ctx (drop 2 items) (second r))))