Skip to content

Commit 3e8a98d

Browse files
committed
add docstrings & validation to macroexpand & macroexpand-1
1 parent f588611 commit 3e8a98d

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/clj/cljs/core.clj

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,11 +1973,24 @@
19731973
(defmacro load-file* [f]
19741974
`(. js/goog (~'nodeGlobalRequire ~f)))
19751975

1976-
(defmacro macroexpand-1 [[quote form]]
1977-
`(quote ~(ana/macroexpand-1 &env form)))
1978-
1979-
(defmacro macroexpand [[quote form]]
1980-
(core/let [env &env]
1976+
(defmacro macroexpand-1
1977+
"If form represents a macro form, returns its expansion,
1978+
else returns form."
1979+
[quoted]
1980+
(core/assert (core/= (core/first quoted) 'quote)
1981+
"Argument to macroexpand-1 must be quoted")
1982+
(core/let [form (second quoted)]
1983+
`(quote ~(ana/macroexpand-1 &env form))))
1984+
1985+
(defmacro macroexpand
1986+
"Repeatedly calls macroexpand-1 on form until it no longer
1987+
represents a macro form, then returns it. Note neither
1988+
macroexpand-1 nor macroexpand expand macros in subforms."
1989+
[quoted]
1990+
(core/assert (core/= (core/first quoted) 'quote)
1991+
"Argument to macroexpand must be quoted")
1992+
(core/let [form (second quoted)
1993+
env &env]
19811994
(core/loop [form' (ana/macroexpand-1 env form)]
19821995
(core/if-not (core/identical? form form')
19831996
(recur (ana/macroexpand-1 env form))

0 commit comments

Comments
 (0)