Re: Deterministic macro expansion for Clojure?

2015-03-31 Thread Karsten Schmidt
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

Re: Deterministic macro expansion for Clojure?

2015-03-31 Thread Mike Haney
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

Re: Deterministic macro expansion for Clojure?

2015-03-30 Thread David James
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

Re: Deterministic macro expansion for Clojure?

2015-03-27 Thread Ben Wolfson
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)]

Re: Deterministic macro expansion for Clojure?

2015-03-27 Thread David James
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

Re: Deterministic macro expansion for Clojure?

2015-03-23 Thread Chris Ford
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

Re: Deterministic macro expansion for Clojure?

2015-03-23 Thread Sean Corfield
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

Re: Deterministic macro expansion for Clojure?

2015-03-22 Thread Di Xu
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

Deterministic macro expansion for Clojure?

2015-03-22 Thread 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 like this: ``` (defmacro lol [] `(let [a# 1] (inc a#))) (with-predictable-gensym-starting-from-zero (macroexpand '(lol)) ;; => `(let [a0 1] (inc a0)) ``` -- Y