Skip to content

Commit eca7f7d

Browse files
committed
Implement macroexpand-1.
1 parent 2c4012a commit eca7f7d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

pixie/stdlib.pxi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,24 @@ Expands to calls to `extend-type`."
23112311
([f col]
23122312
(transduce (map f) conj col)))
23132313

2314+
(defn macroexpand-1 [form]
2315+
{:doc "If form is a macro call, returns the expanded form.
2316+
2317+
Does nothing if not a macro call."
2318+
:signatures [[form]]
2319+
:examples [["(macroexpand-1 '(when condition this and-this))"
2320+
nil `(if condition (do this and-this))]
2321+
["(macroexpand-1 ())" nil ()]
2322+
["(macroexpand-1 [1 2])" nil [1 2]]]}
2323+
(if (or (not (list? form))
2324+
(= () form))
2325+
form
2326+
(let [[sym & args] form
2327+
fvar (resolve sym)]
2328+
(if (and fvar (macro? @fvar))
2329+
(apply @fvar args)
2330+
form))))
2331+
23142332
(def *1)
23152333
(def *2)
23162334
(def *3)

0 commit comments

Comments
 (0)