core: move promoting/unchecked arithmetic aliases, int?, num to the overlay
Jolt numbers don't overflow, so +'/-'/*'/inc'/dec' and the whole unchecked-* family are just the checked ops — now one-line defs in core/20-coll.clj instead of ~25 seed bindings. int? and num move the same way. unchecked-divide-int now goes through quot, so dividing by zero throws like the JVM instead of silently truncating infinity. unchecked-int/long gain char handling via int, matching Clojure ((unchecked-int \a) => 97). The masking byte/short/char coercions are not aliases and stay in the seed for a later round. Also drops a second duplicate set of unchecked defns that was shadowing the first at module load.
This commit is contained in:
parent
826bee29d4
commit
9ac0f54e72
3 changed files with 73 additions and 39 deletions
|
|
@ -848,3 +848,37 @@
|
|||
;; there, so vector? can't separate them and lists read as ifn?.
|
||||
(defn ifn? [x]
|
||||
(or (fn? x) (keyword? x) (symbol? x) (map? x) (set? x) (vector? x) (var? x)))
|
||||
|
||||
;; Auto-promoting (') and unchecked arithmetic. Jolt numbers don't overflow,
|
||||
;; so all of these are the checked ops; fixed arities mirror Clojure's
|
||||
;; signatures. unchecked-divide-int goes through quot, so dividing by zero
|
||||
;; throws as on the JVM (the old seed fn silently truncated infinity).
|
||||
(def +' +)
|
||||
(def -' -)
|
||||
(def *' *)
|
||||
(def inc' inc)
|
||||
(def dec' dec)
|
||||
(defn unchecked-add [x y] (+ x y))
|
||||
(defn unchecked-subtract [x y] (- x y))
|
||||
(defn unchecked-multiply [x y] (* x y))
|
||||
(defn unchecked-negate [x] (- x))
|
||||
(defn unchecked-inc [x] (+ x 1))
|
||||
(defn unchecked-dec [x] (- x 1))
|
||||
(def unchecked-add-int unchecked-add)
|
||||
(def unchecked-subtract-int unchecked-subtract)
|
||||
(def unchecked-multiply-int unchecked-multiply)
|
||||
(def unchecked-negate-int unchecked-negate)
|
||||
(def unchecked-inc-int unchecked-inc)
|
||||
(def unchecked-dec-int unchecked-dec)
|
||||
(defn unchecked-divide-int [x y] (quot x y))
|
||||
(defn unchecked-remainder-int [x y] (rem x y))
|
||||
(defn unchecked-int [x] (int x))
|
||||
(def unchecked-long unchecked-int)
|
||||
|
||||
;; int? is integer? on jolt: one number type, so fixed-precision and
|
||||
;; arbitrary-precision integers coincide.
|
||||
(defn int? [x] (integer? x))
|
||||
|
||||
;; num: Clojure coerces to java.lang.Number; jolt just checks.
|
||||
(defn num [x]
|
||||
(if (number? x) x (throw (str "num requires a number, got: " x))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue