core: move nthrest/abs/NaN?/object?/undefined?/keyword-identical? to overlay

Fifth pure-fn batch (jolt-1j0 phase 2), 6 leaf fns. nthrest uses the canonical
loop form (same neutral 13/1/0 on nthrest.cljc as the prior Janet version; the
1 fail is a pre-existing platform-conditional case). object?/undefined? are
always false on Jolt.

conformance 218/218 x3, clojure-test-suite 3928, core-bench A/B noise-only.
This commit is contained in:
Yogthos 2026-06-06 23:34:31 -04:00
parent 4aec21e603
commit 185cf30c1d
2 changed files with 19 additions and 18 deletions

View file

@ -121,3 +121,22 @@
(defn completing (defn completing
([f] (completing f identity)) ([f] (completing f identity))
([f cf] (fn ([] (f)) ([x] (cf x)) ([x y] (f x y))))) ([f cf] (fn ([] (f)) ([x] (cf x)) ([x y] (f x y)))))
;; Canonical loop form: short-circuits on an empty/nil coll before examining n
;; (so (nthrest nil n) is nil without a number check), matching Clojure.
(defn nthrest [coll n]
(loop [n n xs coll]
(if (and (pos? n) (seq xs))
(recur (dec n) (rest xs))
xs)))
(defn abs [x] (if (neg? x) (- 0 x) x))
(defn NaN? [x]
(if (number? x) (not (= x x)) (throw (str "NaN? requires a number"))))
;; No distinct host object / undefined types on Jolt.
(defn object? [x] false)
(defn undefined? [x] false)
(defn keyword-identical? [a b] (= a b))

View file

@ -223,7 +223,6 @@
(defn core-max [& args] (each x args (need-num x "max")) (apply max args)) (defn core-max [& args] (each x args (need-num x "max")) (apply max args))
(defn core-min [& args] (each x args (need-num x "min")) (apply min args)) (defn core-min [& args] (each x args (need-num x "min")) (apply min args))
(defn core-abs [x] (if (neg? x) (- 0 x) x))
(defn core-rand [] (math/random)) (defn core-rand [] (math/random))
(defn core-rand-int [n] (math/floor (* (math/random) n))) (defn core-rand-int [n] (math/floor (* (math/random) n)))
@ -3071,13 +3070,6 @@
(var i 0) (while (< i (length c)) (array/push r (in c i)) (+= i n)) (var i 0) (while (< i (length c)) (array/push r (in c i)) (+= i n))
(tuple/slice (tuple ;r))))) (tuple/slice (tuple ;r)))))
(defn core-nthrest [coll n]
(when (not (number? n)) (error "nthrest requires a numeric count"))
(if (nil? coll) nil
(let [c (realize-for-iteration coll)
start (max 0 (min n (length c)))] # negative n -> whole coll
(tuple/slice (tuple ;(array/slice c start))))))
# filterv now lives in the Clojure collection tier (core/20-coll.clj). # filterv now lives in the Clojure collection tier (core/20-coll.clj).
# mapv lives in the Clojure kernel tier — core/00-kernel.clj. # mapv lives in the Clojure kernel tier — core/00-kernel.clj.
@ -3278,7 +3270,6 @@
(defn core-construct-proxy [c & args] (error "construct-proxy: not supported in Jolt")) (defn core-construct-proxy [c & args] (error "construct-proxy: not supported in Jolt"))
(defn core-init-proxy [proxy mappings] proxy) (defn core-init-proxy [proxy mappings] proxy)
(defn core-get-proxy-class [& interfaces] (error "get-proxy-class: not supported in Jolt")) (defn core-get-proxy-class [& interfaces] (error "get-proxy-class: not supported in Jolt"))
(defn core-undefined? [x] false)
(def- char-escapes (def- char-escapes
{10 "\\n" 9 "\\t" 13 "\\r" 12 "\\f" 8 "\\b" 34 "\\\"" 92 "\\\\"}) {10 "\\n" 9 "\\t" 13 "\\r" 12 "\\f" 8 "\\b" 34 "\\\"" 92 "\\\\"})
@ -3362,7 +3353,6 @@
(defn core-double? [x] (and (number? x) (not (intval? x)))) (defn core-double? [x] (and (number? x) (not (intval? x))))
(defn core-float? [x] (and (number? x) (not (intval? x)))) (defn core-float? [x] (and (number? x) (not (intval? x))))
(defn core-infinite? [x] (and (number? x) (= (math/abs x) math/inf))) (defn core-infinite? [x] (and (number? x) (= (math/abs x) math/inf)))
(defn core-NaN? [x] (if (number? x) (not= x x) (error "NaN? requires a number")))
# Jolt has no ratio type, so numerator/denominator have no valid input (Clojure # Jolt has no ratio type, so numerator/denominator have no valid input (Clojure
# requires a Ratio and throws otherwise). # requires a Ratio and throws otherwise).
(defn core-numerator [x] (error "numerator requires a ratio (Jolt has no ratios)")) (defn core-numerator [x] (error "numerator requires a ratio (Jolt has no ratios)"))
@ -3393,8 +3383,6 @@
(defn core-comparator [pred] (defn core-comparator [pred]
(fn [a b] (cond (truthy? (pred a b)) -1 (truthy? (pred b a)) 1 true 0))) (fn [a b] (cond (truthy? (pred a b)) -1 (truthy? (pred b a)) 1 true 0)))
(defn core-keyword-identical? [a b] (= a b))
(defn core-object? [x] false)
(defn core-tagged-literal [tag form] @{:jolt/type :jolt/tagged-literal :tag tag :form form}) (defn core-tagged-literal [tag form] @{:jolt/type :jolt/tagged-literal :tag tag :form form})
(defn core-ensure-reduced [x] (if (core-reduced? x) x (core-reduced x))) (defn core-ensure-reduced [x] (if (core-reduced? x) x (core-reduced x)))
(defn core-halt-when [pred & rest] (defn core-halt-when [pred & rest]
@ -3586,7 +3574,6 @@
"quot" core-quot "quot" core-quot
"max" core-max "max" core-max
"min" core-min "min" core-min
"abs" core-abs
"rand" core-rand "rand" core-rand
"rand-int" core-rand-int "rand-int" core-rand-int
"=" core-= "=" core-=
@ -3647,7 +3634,6 @@
"double?" core-double? "double?" core-double?
"float?" core-float? "float?" core-float?
"infinite?" core-infinite? "infinite?" core-infinite?
"NaN?" core-NaN?
"numerator" core-numerator "numerator" core-numerator
"denominator" core-denominator "denominator" core-denominator
"list*" core-list* "list*" core-list*
@ -3662,8 +3648,6 @@
"future-cancel" core-future-cancel "future-cancel" core-future-cancel
"future-cancelled?" core-future-cancelled? "future-cancelled?" core-future-cancelled?
"comparator" core-comparator "comparator" core-comparator
"keyword-identical?" core-keyword-identical?
"object?" core-object?
"tagged-literal" core-tagged-literal "tagged-literal" core-tagged-literal
"ensure-reduced" core-ensure-reduced "ensure-reduced" core-ensure-reduced
"unreduced" core-unreduced "unreduced" core-unreduced
@ -3718,7 +3702,6 @@
"reduced" core-reduced "reduced" core-reduced
"reduced?" core-reduced? "reduced?" core-reduced?
"take-nth" core-take-nth "take-nth" core-take-nth
"nthrest" core-nthrest
"empty" core-empty "empty" core-empty
"rseq" core-rseq "rseq" core-rseq
"shuffle" core-shuffle "shuffle" core-shuffle
@ -3886,7 +3869,6 @@
"construct-proxy" core-construct-proxy "construct-proxy" core-construct-proxy
"init-proxy" core-init-proxy "init-proxy" core-init-proxy
"get-proxy-class" core-get-proxy-class "get-proxy-class" core-get-proxy-class
"undefined?" core-undefined?
"char-escape-string" core-char-escape-string "char-escape-string" core-char-escape-string
"char-name-string" core-char-name-string "char-name-string" core-char-name-string
"subseq" core-subseq "subseq" core-subseq