Skip to content

Instantly share code, notes, and snippets.

@borkdude
Created May 17, 2022
Embed
What would you like to do?
export macro
foo=> (defmacro export [& var-names]
(let [var-names (set var-names)]
(doseq [[k v] (ns-publics *ns*)]
(when-not (contains? var-names k)
(alter-meta! v assoc :private true)))))
#'foo/export
foo=> (defn foo [])
#'foo/foo
foo=> (defn bar [])
#'foo/bar
foo=> (export foo)
nil
foo=> (ns bar)
nil
bar=> foo/foo
#object[foo$foo 0x5ecba515 "foo$foo@5ecba515"]
bar=> foo/bar
Syntax error (IllegalStateException) compiling at (REPL:0:0).
var: foo/bar is not public
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment