On Apr 24, 2:57 am, Kevin Van Horn kvanh...@ksvanhorn.com wrote:
1. bit-and, bit-or, and bit-xor only take two arguments. These are
all associative operations, and as such should take an arbitrary
number of arguments for the same reason that + and * take arbitrary
number of arguments:
On Fri, Apr 24, 2009 at 6:33 AM, Dimiter malkia Stanev
mal...@gmail.com wrote:
Here's even more concise version:
(defmacro mo [op args]
(reduce (fn [ ab#] (cons op ab#)) args))
Or maybe just:
(defn mo [op args] (reduce op args))
I don't think that's the point, though. Why not allow
Or maybe just:
(defn mo [op args] (reduce op args))
I believe that won't make clojure make a faster code, but I might be
wrong.
I think the macroexpansion is the right thing if you want speed, as it
seems clojure could optimize well this:
(+ a b)
while it can't optimize this well
(+ a b c)
I'm writing an application that needs fast, high-quality random number
generation, so I've been implementing a Mersenne Twister random number
generator. I'm finding that bit-twiddling in Clojure can be a bit
awkward. Here are some specifics:
1. bit-and, bit-or, and bit-xor only take two
You can make your own macro to do that:
(defmacro mo [op args]
(reduce (fn [a# b#] (cons op [a# b#])) args))
(mo + 1 2 3 4)
(print expanded= (macroexpand '(mo + 1 2 3 4)) \n)
;expanded= (+ (+ (+ 1 2) 3) 4)
On Apr 23, 5:57 pm, Kevin Van Horn kvanh...@ksvanhorn.com wrote:
I'm writing an
Here's even more concise version:
(defmacro mo [op args]
(reduce (fn [ ab#] (cons op ab#)) args))
On Apr 23, 9:23 pm, Dimiter \malkia\ Stanev mal...@gmail.com
wrote:
You can make your own macro to do that:
(defmacro mo [op args]
(reduce (fn [a# b#] (cons op [a# b#])) args))
(mo + 1