On Jun 22, 8:24 pm, arasoft <t...@arasoft.de> wrote:
> I just wrote my first practice macro, first without and then with
> syntax quoting:
>
> (defmacro take-until1 [function sq]
>   (list 'take-while (list 'fn (vector 'x) (list 'not (list function
> 'x))) sq))
>
> (defmacro take-until2 [function sq]
>   `(take-while (fn [x#] (not (~function x#))) ~sq))
>
> Both seem to work, but macroexpand shows different formats:
>
> (macroexpand '(take-until1 #(> % 10) (iterate inc 1)))
> -> (take-while (fn [x] (not ((fn* [p1__502] (> p1__502 10)) x)))
> (iterate inc 1))
>
> (macroexpand '(take-until2 #(> % 10) (iterate inc 1)))
> (clojure.core/take-while (clojure.core/fn [x__405__auto__]
> (clojure.core/not ((fn* [p1__506] (> p1__506 10)) x__405__auto__)))
> (iterate inc 1))
>
> While I prefer the syntax of macro 2, I like the expand format of
> macro 1.
> Is there any way to get the best of both worlds?

The only real differences I see are the name-qualifying, p1_506
instead of p1_502, and x__405__auto__ instead of x.

The only part I've ever found annoying was the name-qualifying. When I
want to declutter the results of macroexpand, I just paste into a text
editor and do a replace of clojure.core/ with the empty string.

P.S. "(complement f)" has the same effect as "(fn [foo] (not (f
foo)))".

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to