Reader macros are evaluated at read time, not macroexpansion time. Read
time happens during reading - the process in which the characters in a file
are read into the Lisp forms Clojure supports. Therefore ^:private is not
syntax which can be manipulated in a macro, because by the point the macro
is evaluated that form is no longer present.
Check out the source for defn- (you can find it in a REPL by calling
(clojure.repl/source defn-)
(defmacro defn-
"same as defn, yielding non-public def"
{:added "1.0"}
[name & decls]
(list* `defn (with-meta name (assoc (meta name) :private true)) decls))
(defmacro def-
"same as def, yielding non-public def"
([name] `(def- ~name nil))
([name expr]
(list `def (with-meta name (assoc (meta name) :private true)) expr)))
On Thursday, May 7, 2015 at 10:12:39 AM UTC-4, Stig Brautaset wrote:
>
> Is it because the def form can also be ^:dynamic?
>
> At any rate, I did an attempt at my first macro to create a (def- ...)
> form, but it doesn't seem to work. Can you not attach metadata in a macro?
>
> (defmacro def-
> "Why (defn- private-fn ...) but (def ^:private var ...)?"
> [sym & body]
> `(def ^:private ~sym ~@body))
>
> ;; => #'user/def-
> user> (macroexpand '(def- blah "foo bar quux"))
> ;; => (def blah "foo bar quux")
>
> Stig
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.