On similar lines as Ben suggested (but different use case), here's
what I've been doing to rewrite expressions:
(defmacro rewrite-v2
[src & body]
(let [[a x y] (repeatedly gensym)]
`(let [~(with-meta a {:tag "doubles"}) ~src
~x (aget ~a 0)
~y (aget ~a 1)]
~@(po
You also might want to check out this talk http://youtu.be/YHctJMUG8bI
In part of the talk, he describes how they generate symbols deterministically
to use in query fragments that can be predictably combined into Datomic
queries. Different application, but mostly the same requirements as you st
Thanks! A great suggestion. I'll try it.
On Friday, March 27, 2015 at 8:56:21 PM UTC-4, Ben wrote:
>
> One way you can get what you want is to give up on the auto-gensym feature
> of the #-terminated identifiers, and call gensym directly, enabling it to
> be mocked out with with-redefs. E.g. ins
One way you can get what you want is to give up on the auto-gensym feature
of the #-terminated identifiers, and call gensym directly, enabling it to
be mocked out with with-redefs. E.g. instead of:
(defmacro m1
[x f]
`(let [x# ~x]
(~f x#)))
do
(defmacro m1 [x f]
(let [x-sym (gensym)]
I agree with this motivation behind this request, which I explain in more
detail
here:
http://stackoverflow.com/questions/16745135/how-to-test-a-clojure-macro-that-uses-gensyms
We should be able to test the behavior *and* the macroexpansion. (Most
things in life are not simple either/or decisi
I think it's useful to think of macros as an odd form of I/O. Just as you
would separate out your templating from your domain functions, separate out
your defmacro from regular functions that just happen to manipulate
symbols. These functions will be easier to test.
On 23 March 2015 at 16:23, Sean
On Mar 22, 2015, at 7:52 PM, myguidingstar
wrote:
> I wonder if there is any way to make macro expansion in Clojure
> deterministic. That would be useful in unit tests.
I’d be very interested to understand your use case… Testing what the macro
expands to seems like it is test the macro system
Well, I think it's nondeterministic by design, we usually just test its
behavior, not the form it expanded to.
2015-03-23 10:52 GMT+08:00 myguidingstar :
> Hi all,
> I wonder if there is any way to make macro expansion in Clojure
> deterministic. That would be useful in unit tests. Something lik
Hi all,
I wonder if there is any way to make macro expansion in Clojure
deterministic. That would be useful in unit tests. Something like this:
```
(defmacro lol []
`(let [a# 1] (inc a#)))
(with-predictable-gensym-starting-from-zero
(macroexpand '(lol))
;; => `(let [a0 1] (inc a0))
```
--
Y