bit-and, bit-or arity question

2 views
Skip to first unread message

ntu...@googlemail.com

unread,
Dec 21, 2008, 6:14:57 PM12/21/08
to Clojure
Why do "bit-or" and "bit-and" only accept 2 arguments? "or" and "and"
accept an arbitrary number and I think it is useful to modifiy "bit-
or" and "bit-and" to accept 2 or more, for example:

(defn my-bit-or [x y & rest]
(reduce #(clojure.lang.Numbers/or %1 %2) (list* x y rest)))

What does the group think?

Randall R Schulz

unread,
Dec 21, 2008, 6:39:06 PM12/21/08
to clo...@googlegroups.com

The group thinks only in group-think, and hence is meaningless...

But I (the individual) agree, modulo a proper overloading pattern to
afford minimal overhead for the two-argument form.


RRS

ntu...@googlemail.com

unread,
Dec 22, 2008, 11:32:44 AM12/22/08
to Clojure
On Dec 22, 12:39 am, Randall R Schulz <rsch...@sonic.net> wrote:
> But I (the individual) agree, modulo a proper overloading pattern to
> afford minimal overhead for the two-argument form.


You mean like:

(defn bit-or
([] 0)
([x] x)
([x y] (clojure.lang.Numbers/or x y))
([x y & rest]
(reduce #(clojure.lang.Numbers/or %1 %2) (list* x y rest))))

(defn bit-and
([] 1)
([x] x)
([x y] (clojure.lang.Numbers/and x y))
([x y & rest]
(reduce #(clojure.lang.Numbers/and %1 %2) (list* x y rest))))

Btw. wouldn't it be handy if static Java methods could be handled
directly as functions? So the implementations would become:

(defn bit-or
([] 0)
([x] x)
([x y] (clojure.lang.Numbers/or x y))
([x y & rest]
(reduce clojure.lang.Numbers/or (list* x y rest))))

(defn bit-and
([] 1)
([x] x)
([x y] (clojure.lang.Numbers/and x y))
([x y & rest]
(reduce clojure.lang.Numbers/and (list* x y rest))))

Much clearer IMO.

Cheers!
Reply all
Reply to author
Forward
0 new messages