Re: Bit-level operations

2009-04-24 Thread Christophe Grand
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:

Re: Bit-level operations

2009-04-23 Thread Dimiter "malkia" Stanev
> 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

Re: Bit-level operations

2009-04-23 Thread Michael Wood
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

Re: Bit-level operations

2009-04-23 Thread ntu...@googlemail.com
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

Re: Bit-level operations

2009-04-23 Thread Dimiter "malkia" Stanev
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

Re: Bit-level operations

2009-04-23 Thread Dimiter "malkia" Stanev
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

Bit-level operations

2009-04-23 Thread Kevin Van Horn
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