integer (32-bit) bit operations not available

Description

It would be nice if Clojure provided implementations for all Java
operators, using primitive types. While Clojures numbers handling is
nice, there are algorithms for which it is a pain.

Clojure currently provides a number of functions to deal with this:
unchecked-add and unchecked-add-int, for instance. But, not all of the
Java operators are accessible in this way, at least to my knowledge;
specifically, the "&" and "|" operators have no function
equivalents. Actually, they are still present in source (Numbers.java)
but have been commented out. I can't really understand the reason for
this omission.

Environment

None

Activity

Show:
import
June 30, 2017, 5:36 PM

Comment made by: phillord

They are in the API. unchecked-add-int, unchecked-multiply-int are all surfaced in core. Just the arithmetic operators, but not the bitwise.

Anyway, thanks for the explanation; at least, now the situation is clear. I can either port the entire algorithms or just these operators out to Java.

Alex Miller
June 30, 2017, 5:53 PM

The Java classes are the implementation, not the API.

import
June 30, 2017, 6:42 PM

Comment made by: phillord

user=> clojure.core/unchecked-add-int
#object[clojure.core$unchecked_add_int 0x479395d7 "clojure.core$unchecked_add_int@479395d7"]
user=> (clojure.core/unchecked-add-int 1 2)
3
user=> (type (clojure.core/unchecked-add-int 1 2))
java.lang.Integer

So, int operations in the API, yes? But just for the arithmetic operators and not for the bitwise ones.

Ghadi Shayban
June 30, 2017, 7:59 PM

Symmetry is not one of the stronger API design motivations

Alex Miller
June 30, 2017, 8:59 PM

Sorry, yes - some int operations are in the Clojure api. There are no plans to add the int bit ops.

Declined

Assignee

Unassigned

Reporter

import

Labels

Approval

None

Patch

None

Priority

Minor