Re: Deterministic macro expansion for Clojure?
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 stated. -- 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.
Re: Deterministic macro expansion for Clojure?
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)] ~@(postwalk-replace {'x x 'y y} body This allows me to write things like: (rewrite-v2 buf (Math/sqrt (+ (* x x) (* y y ...and replaces all `x` `y` with values looked up from the given array. More elaborate examples/versions of this are here: https://github.com/thi-ng/geom/blob/master/geom-core/src/vector.org#vec2-1 Hth! On 31 March 2015 at 14:51, Mike Haney txmikes...@gmail.com wrote: 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 stated. -- 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. -- Karsten Schmidt http://postspectacular.com | http://toxiclibs.org | http://toxi.co.uk -- 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.
Re: Deterministic macro expansion for Clojure?
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. instead of: (defmacro m1 [x f] `(let [x# ~x] (~f x#))) do (defmacro m1 [x f] (let [x-sym (gensym)] `(let [~x-sym ~x] (~f ~x-sym You can then do something like (defn new-gensym [] (let [counter (atom 0)] (fn [ [extra]] (symbol (str (or extra G_) (swap! counter inc)) (with-redefs [gensym (new-gensym)] (macroexpand-1 '(m1 1 inc))) (not tested) On Fri, Mar 27, 2015 at 5:50 PM, David James david...@gmail.com javascript: wrote: 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 decisions. Don't believe people that tell you otherwise.) On Monday, March 23, 2015 at 12:58:49 PM UTC-4, Chris Ford wrote: 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 Corfield se...@corfield.org wrote: On Mar 22, 2015, at 7:52 PM, myguidingstar phuthuycuo...@gmail.com 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 itself, not your own code. Surely in a unit test you’d want to test the _behavior_ of the code instead? Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- Ben Wolfson Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure. [Larousse, Drink entry] -- 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.
Re: Deterministic macro expansion for Clojure?
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 decisions. Don't believe people that tell you otherwise.) On Monday, March 23, 2015 at 12:58:49 PM UTC-4, Chris Ford wrote: 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 Corfield se...@corfield.org javascript: wrote: On Mar 22, 2015, at 7:52 PM, myguidingstar phuthuycuo...@gmail.com javascript: 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 itself, not your own code. Surely in a unit test you’d want to test the _behavior_ of the code instead? Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.com javascript: Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+u...@googlegroups.com javascript: 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+u...@googlegroups.com javascript:. For more options, visit https://groups.google.com/d/optout. -- 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.
Re: Deterministic macro expansion for Clojure?
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)] `(let [~x-sym ~x] (~f ~x-sym You can then do something like (defn new-gensym [] (let [counter (atom 0)] (fn [ [extra]] (symbol (str (or extra G_) (swap! counter inc)) (with-redefs [gensym (new-gensym)] (macroexpand-1 '(m1 1 inc))) (not tested) On Fri, Mar 27, 2015 at 5:50 PM, David James davidcja...@gmail.com wrote: 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 decisions. Don't believe people that tell you otherwise.) On Monday, March 23, 2015 at 12:58:49 PM UTC-4, Chris Ford wrote: 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 Corfield se...@corfield.org wrote: On Mar 22, 2015, at 7:52 PM, myguidingstar phuthuycuo...@gmail.com 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 itself, not your own code. Surely in a unit test you'd want to test the _behavior_ of the code instead? Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@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+u...@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+u...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- 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. -- Ben Wolfson Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure. [Larousse, Drink entry] -- 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.
Re: Deterministic macro expansion for Clojure?
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 phuthuycuoimayhut...@gmail.com: 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)) ``` -- 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. -- 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.
Re: Deterministic macro expansion for Clojure?
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 Corfield s...@corfield.org wrote: On Mar 22, 2015, at 7:52 PM, myguidingstar phuthuycuoimayhut...@gmail.com 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 itself, not your own code. Surely in a unit test you’d want to test the _behavior_ of the code instead? Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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. -- 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.
Re: Deterministic macro expansion for Clojure?
On Mar 22, 2015, at 7:52 PM, myguidingstar phuthuycuoimayhut...@gmail.com 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 itself, not your own code. Surely in a unit test you’d want to test the _behavior_ of the code instead? Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ Perfection is the enemy of the good. -- Gustave Flaubert, French realist novelist (1821-1880) -- 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.
Deterministic macro expansion for Clojure?
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)) ``` -- 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.