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 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 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 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: so you can write, e.g.,
>
> >    (op a1 a2 a3 a4)
>
> > instead of
>
> >    (op (op (op a1 a2) a3) a4)
>
> > 2. There is no direct support for word-level, unsigned shifts.  That  
> > is, I want to treat an int as the equivalent 32-bit unsigned value  
> > when I do the shift, shifting in 0 bits and dropping the bits that  
> > shift past the word boundaries.
>
> > It took a while to figure out how to do this correctly; the biggest  
> > problem was avoiding the propagation of the sign bit on a right  
> > shift.  After experimenting around for a while I figured out that  
> > these will work:
>
> > * Left-shift x by n bits: (int (bit-shift-left x n)).
>
> > * Right-shift x by n bits: (int (bit-shift-right (bit-and intmask x) n))
> >    where intmask = 2^32 - 1.
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to