letfn is a macro over a letfn* special form (Clojure semantics)
jolt modelled letfn as a special form directly, so (macroexpand-1 '(letfn …)) returned the form unchanged. Clojure's letfn is a macro that expands to letfn*, and macroexpansion tooling (tools.macro, tools.analyzer) depends on that — its special-form handlers key on letfn*, not letfn. Split it the Clojure way: - letfn* is now the special form (analyzer), taking flat name/fn-form pairs [name1 fn1 name2 fn2 …] — the letrec :let lowering is unchanged. - letfn is a macro (00-syntax) turning each (name [params] body*) spec into a name + (fn name [params] body*) binding, so it expands to letfn*. So (macroexpand-1 '(letfn [(f [x] x)] (f 1))) now yields (letfn* [f (fn f [x] x)] (f 1)), and clojure.tools.macro passes its whole suite (macrolet / symbol-macrolet / mexpand-all). Listed in docs + site. make test green (+1 corpus row, 0 new divergences), shakesmoke byte-identical. One re-mint (analyzer + the letfn macro); selfhost holds.
This commit is contained in:
parent
7891fa0d55
commit
21cd88deee
6 changed files with 341 additions and 330 deletions
|
|
@ -159,6 +159,15 @@
|
|||
(defmacro declare [& syms]
|
||||
`(do ~@(map (fn* [s] `(def ~s)) syms)))
|
||||
|
||||
;; letfn is a macro over the letfn* special form, matching Clojure: each
|
||||
;; (name [params] body*) spec becomes a name + a (fn name [params] body*) binding.
|
||||
;; So (macroexpand-1 '(letfn …)) yields the letfn* form macroexpansion tooling
|
||||
;; (tools.macro / tools.analyzer) expects, instead of an opaque special form.
|
||||
(defmacro letfn [fnspecs & body]
|
||||
(cons 'letfn*
|
||||
(cons (reduce (fn [acc s] (conj (conj acc (first s)) (cons 'fn s))) [] fnspecs)
|
||||
body)))
|
||||
|
||||
;; destructure — Clojure's binding-vector expander.
|
||||
;; Turns a binding vector that may contain destructuring
|
||||
;; patterns into a plain binding vector (alternating symbol / init-form) built from
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue