Dimiter "malkia" Stanev a écrit :
>> 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:
> 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
On Fri, Apr 24, 2009 at 6:33 AM, Dimiter "malkia" Stanev
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 bit-and an
On Apr 24, 2:57 am, Kevin Van Horn 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:
I totally agree. I
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"
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 2 3
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 wrote:
> I'm writing an application that ne
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