Recently I've been working on bits of code that require me to type in fairly
long sequences of math operations. I found it tedious to convert these to
type hinted binary operations so I've created the following truly simplistic
macro:

http://gist.github.com/364328

It lets you write things like this:

(prim float (* (/ (* (/ (prim int mod (prim float + x n) 45) 5.0) 40.0)
360.0)
                           (* Math/PI 2.0)))

It handles -> so you can do this as well:

(prim float (-> 4 (+ 5) (+ (* 6 7)) (+ 8)))

Basically (prim type expr) assumes you want to recursively replace all
arithmetic ops. (prim type op expr & rest) doesn't make this assumption.
Also to be clear, this just a hack, it will type cast already casted locals
for example.

This works for me, hopefully someone else finds this useful or can suggest
improvements.

David

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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to