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 <[email protected]> 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 [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.