On Thu, Mar 15 2018, Didier wrote:
I feel it would be really cool to be able to factor some input to macros into constants, is this something I could open a ticket for, to extend ^:const so it can inline all literal values and also does the inlining before macroexpanssion so that the above would work?
Macroexpansion is given the raw forms that are read, and I think that's a good thing. Inside a macro you can always call macroexpand yourself if you want to (or resolve values another way) but there's no way to "undo" automatic macroexpansion.
As one particular example, how would this work in your world? If the `bar` is replaced ahead of time in the usage of `l` then it cannot be shadowed as an identifier.
(def ^:const bar {:a 100}) (defmacro l [name value & body] `(let [~name ~value] ~@body)) (l bar 1 (+ bar 1))If you want to factor out things for macros (particularly macros that you don't control) you can try doing so at read time, with something that evaluates at read time, like so:
(def bar {:a 100}) (defmacro foo [x] (:a x)) (foo #=(eval bar)) ;; => 100It's a bit messy, but it draws attention to the fact that there's something unusual happening with evaluation order.
Carlo -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: PGP signature