Renaming: String.count -> String.length, Array.count -> Array.length

Issue #236
This commit is contained in:
Chris Hall 2018-05-20 17:57:51 +10:00
parent 5c280fea4b
commit 7c1dd210d7
29 changed files with 152 additions and 152 deletions

View File

@ -8,10 +8,10 @@
(ignore (let-do [a [0]] (ignore (let-do [a [0]]
(for [i 1 n] (for [i 1 n]
(set! a (Array.push-back a i))) (set! a (Array.push-back a i)))
(assert (= n (Array.count &a))) (assert (= n (Array.length &a)))
(for [i 1 n] (for [i 1 n]
(set! a (Array.pop-back a))) (set! a (Array.pop-back a)))
(assert (= 1 (Array.count &a)))))) (assert (= 1 (Array.length &a))))))
(defn main [] (defn main []
(do (do

View File

@ -9,12 +9,12 @@
(defn some-subarray [] (defn some-subarray []
(let-do [a (replicate n &1) (let-do [a (replicate n &1)
b (subarray &a 0 (/ n 2))] b (subarray &a 0 (/ n 2))]
(assert (= (/ n 2) (count &b))))) (assert (= (/ n 2) (length &b)))))
(defn perform-bench [new-n] (defn perform-bench [new-n]
(do (do
(set! n new-n) (set! n new-n)
(println* "\nTaking sub-array of array with count " n) (println* "\nTaking sub-array of array with length " n)
(bench some-subarray))) (bench some-subarray)))
(defn main [] (defn main []

View File

@ -10,7 +10,7 @@
(defn perform-bench [n] (defn perform-bench [n]
(do (do
(println* "\nSwap with array count " n) (println* "\nSwap with array length " n)
(set! a (Array.replicate n &1)) (set! a (Array.replicate n &1))
(bench some-swapping))) (bench some-swapping)))
@ -20,7 +20,7 @@
(defn perform-mutable-bench [n] (defn perform-mutable-bench [n]
(do (do
(println* "\nMutable swap with array count " n) (println* "\nMutable swap with array length " n)
(set! a (Array.replicate n &1)) (set! a (Array.replicate n &1))
(bench some-mutable-swapping))) (bench some-mutable-swapping)))

View File

@ -17,7 +17,7 @@
(defn perform-bench [new-n] (defn perform-bench [new-n]
(do (do
(set! n new-n) (set! n new-n)
(println* "\nUpdating array with count " n) (println* "\nUpdating array with length " n)
(bench some-updating))) (bench some-updating)))
(defn main [] (defn main []

View File

@ -4,7 +4,7 @@
(defn reduce [f x xs] (defn reduce [f x xs]
(let [total x] (let [total x]
(do (do
(for [i 0 (count xs)] (for [i 0 (length xs)]
(set! total (f &total (nth xs i)))) (set! total (f &total (nth xs i))))
total))) total)))
@ -14,14 +14,14 @@
(doc last "Take the last element of an array.") (doc last "Take the last element of an array.")
(defn last [a] (defn last [a]
@(Array.nth a (Int.dec (Array.count a)))) @(Array.nth a (Int.dec (Array.length a))))
(doc = "Compare two arrays.") (doc = "Compare two arrays.")
(defn = [a b] (defn = [a b]
(if (/= (count a) (count b)) (if (/= (length a) (length b))
false false
(let-do [eq true] (let-do [eq true]
(for [i 0 (count a)] (for [i 0 (length a)]
(when (/= @(nth a i) @(nth b i)) (when (/= @(nth a i) @(nth b i))
(do (do
(set! eq false) (set! eq false)
@ -31,7 +31,7 @@
(doc maximum "Get the maximum in an array (elements must support <).") (doc maximum "Get the maximum in an array (elements must support <).")
(defn maximum [xs] (defn maximum [xs]
(let [result (first xs) (let [result (first xs)
n (count xs)] n (length xs)]
(do (do
(for [i 1 n] (for [i 1 n]
(let [x @(nth xs i)] (let [x @(nth xs i)]
@ -43,7 +43,7 @@
(doc minimum "Get the maximum in an array (elements must support >).") (doc minimum "Get the maximum in an array (elements must support >).")
(defn minimum [xs] (defn minimum [xs]
(let [result (first xs) (let [result (first xs)
n (count xs)] n (length xs)]
(do (do
(for [i 1 n] (for [i 1 n]
(let [x @(nth xs i)] (let [x @(nth xs i)]
@ -70,12 +70,12 @@
(doc suffix-array "Get subarray from start-index.") (doc suffix-array "Get subarray from start-index.")
(defn suffix-array [xs start-index] (defn suffix-array [xs start-index]
(subarray xs start-index (count xs))) (subarray xs start-index (length xs)))
(doc reverse "Reverse an array.") (doc reverse "Reverse an array.")
(defn reverse [a] (defn reverse [a]
(let-do [i 0 (let-do [i 0
j (Int.dec (count &a))] j (Int.dec (length &a))]
(while (Int.< i j) (while (Int.< i j)
(let-do [tmp @(nth &a i)] (let-do [tmp @(nth &a i)]
(aset! &a i @(nth &a j)) (aset! &a i @(nth &a j))
@ -87,7 +87,7 @@
(doc index-of "Get the index of element e in an array.") (doc index-of "Get the index of element e in an array.")
(defn index-of [a e] (defn index-of [a e]
(let-do [idx -1] (let-do [idx -1]
(for [i 0 (count a)] (for [i 0 (length a)]
(when (= (nth a i) &e) (when (= (nth a i) &e)
(do (do
(set! idx i) (set! idx i)
@ -97,7 +97,7 @@
(doc element-count "Count occurrences of element e in an array.") (doc element-count "Count occurrences of element e in an array.")
(defn element-count [a e] (defn element-count [a e]
(let-do [c 0] (let-do [c 0]
(for [i 0 (count a)] (for [i 0 (length a)]
(when (= e (nth a i)) (set! c (Int.inc c)))) (when (= e (nth a i)) (set! c (Int.inc c))))
c)) c))
@ -161,31 +161,31 @@
(doc copy-map "Map over array a using function f (copies the array).") (doc copy-map "Map over array a using function f (copies the array).")
(defn copy-map [f a] (defn copy-map [f a]
(let-do [na (allocate (count a))] (let-do [na (allocate (length a))]
(for [i 0 (count a)] (for [i 0 (length a)]
(aset-uninitialized! &na i (f (nth a i)))) (aset-uninitialized! &na i (f (nth a i))))
na)) na))
(doc sum-count "Returns the sum of counts from an Array of Arrays.") (doc sum-length "Returns the sum of lengths from an Array of Arrays.")
(defn sum-count [xs] (defn sum-length [xs]
(let-do [sum 0 (let-do [sum 0
lxs (Array.count xs)] lxs (Array.length xs)]
(for [i 0 lxs] (for [i 0 lxs]
(set! sum (+ sum (Array.count (Array.nth xs i))))) (set! sum (+ sum (Array.length (Array.nth xs i)))))
sum)) sum))
(doc concat "Returns a new Array which is the concatenation of the provided `xs`.") (doc concat "Returns a new Array which is the concatenation of the provided `xs`.")
(defn concat [xs] (defn concat [xs]
;; This is using a StringBuilder pattern to only perform one allocation and ;; This is using a StringBuilder pattern to only perform one allocation and
;; to only copy each of the incoming Array(s) once. ;; to only copy each of the incoming Array(s) once.
;; This currently performs wasted Array.count calls, as we call it for each ;; This currently performs wasted Array.length calls, as we call it for each
;; Array once here and once in sum-count. ;; Array once here and once in sum-length.
(let-do [j 0 (let-do [j 0
lxs (Array.count xs) lxs (Array.length xs)
result (Array.allocate (sum-count xs))] result (Array.allocate (sum-length xs))]
(for [i 0 lxs] (for [i 0 lxs]
(let-do [arr (Array.nth xs i) (let-do [arr (Array.nth xs i)
len (Array.count arr)] len (Array.length arr)]
(for [k 0 len] (for [k 0 len]
(aset-uninitialized! &result (+ j k) @(Array.nth arr k))) (aset-uninitialized! &result (+ j k) @(Array.nth arr k)))
(set! j (+ j len)))) (set! j (+ j len))))

View File

@ -10,7 +10,7 @@
(doc dir-from-path "Removes the file-name part of a path to a file.") (doc dir-from-path "Removes the file-name part of a path to a file.")
(defn dir-from-path [path] (defn dir-from-path [path]
(let [segments (split-by path &[\/]) (let [segments (split-by path &[\/])
n (dec (count &segments)) n (dec (length &segments))
without-last (prefix-array &segments n)] without-last (prefix-array &segments n)]
(concat &(copy-map append-slash &without-last)))) (concat &(copy-map append-slash &without-last))))

View File

@ -2,20 +2,20 @@
(hidden fmt-internal) (hidden fmt-internal)
(defdynamic fmt-internal [s args] (defdynamic fmt-internal [s args]
(let [idx (String.index-of s \%) (let [idx (String.index-of s \%)
len (String.count s)] len (String.length s)]
(if (= idx -1) (if (= idx -1)
(list 'copy s) ; no more splits found, just return string (list 'copy s) ; no more splits found, just return string
(if (= \% (String.char-at s (inc idx))) ; this is an escaped % (if (= \% (String.char-at s (inc idx))) ; this is an escaped %
(list 'StringCopy.append (list 'StringCopy.append
(list 'copy "%") (list 'copy "%")
(fmt-internal (String.substring s (+ idx 2) len) args)) (fmt-internal (String.substring s (+ idx 2) len) args))
(if (= 0 (count args)) ; we need to insert something, but have nothing (if (= 0 (length args)) ; we need to insert something, but have nothing
(macro-error "error in format string: not enough arguments to format string") (macro-error "error in format string: not enough arguments to format string")
; okay, this is the meat: ; okay, this is the meat:
; get the next % after our escaper ; get the next % after our escaper
(let [next (String.index-of (String.substring s (inc idx) len) \%)] (let [next (String.index-of (String.substring s (inc idx) len) \%)]
(if (= -1 next) (if (= -1 next)
(if (< 1 (count args)) (if (< 1 (length args))
(macro-error "error in format string: too many arguments to format string") (macro-error "error in format string: too many arguments to format string")
(list 'format s (car args))) (list 'format s (car args)))
(let [slice (String.substring s 0 (+ (inc idx) next))] (let [slice (String.substring s 0 (+ (inc idx) next))]

View File

@ -78,11 +78,11 @@
) )
(defdynamic cond-internal [xs] (defdynamic cond-internal [xs]
(if (= (count xs) 0) (if (= (length xs) 0)
(list) (list)
(if (= (count xs) 2) (if (= (length xs) 2)
(macro-error "cond has even number of branches; add an else branch") (macro-error "cond has even number of branches; add an else branch")
(if (= (count xs) 1) (if (= (length xs) 1)
(car xs) (car xs)
(list (list
'if 'if
@ -94,7 +94,7 @@
(cond-internal xs)) (cond-internal xs))
(defmacro for [settings :rest body] ;; settings = variable, from, to, <step> (defmacro for [settings :rest body] ;; settings = variable, from, to, <step>
(if (> (count body) 1) (if (> (length body) 1)
(macro-error "Warning: the body of the 'for' loop can only contain one expression") (macro-error "Warning: the body of the 'for' loop can only contain one expression")
(list (list
'let 'let
@ -103,7 +103,7 @@
'while 'while
(list 'Int.< (car settings) (caddr settings)) (list 'Int.< (car settings) (caddr settings))
(list 'do (list 'do
(if (= (count body) 0) (if (= (length body) 0)
() ()
(if (list? body) (if (list? body)
(car body) (car body)
@ -112,7 +112,7 @@
'set! (car settings) 'set! (car settings)
(list 'Int.+ (list 'Int.+
(car settings) (car settings)
(if (= 4 (count settings)) ;; optional arg for step (if (= 4 (length settings)) ;; optional arg for step
(cadddr settings) (cadddr settings)
1)))))))) 1))))))))
@ -122,12 +122,12 @@
;; Old foreach, what's a better name for this? (it's just 'map' with side effects) ;; Old foreach, what's a better name for this? (it's just 'map' with side effects)
;; (defmacro foreach [f xs] ;; (defmacro foreach [f xs]
;; (list 'for ['i 0 (list 'Array.count (list 'ref xs))] ;; (list 'for ['i 0 (list 'Array.length (list 'ref xs))]
;; (list f (list 'Array.nth (list 'ref xs) 'i)))) ;; (list f (list 'Array.nth (list 'ref xs) 'i))))
(defdynamic foreach-internal [var xs expr] (defdynamic foreach-internal [var xs expr]
(list 'let ['xs xs (list 'let ['xs xs
'len (list 'Array.count 'xs)] 'len (list 'Array.length 'xs)]
(list 'for ['i 0 'len] (list 'for ['i 0 'len]
(list 'let [var (list 'Array.nth 'xs 'i)] (list 'let [var (list 'Array.nth 'xs 'i)]
expr)))) expr))))
@ -138,7 +138,7 @@
(macro-error "Binding has to be an array."))) (macro-error "Binding has to be an array.")))
(defdynamic thread-first-internal [xs] (defdynamic thread-first-internal [xs]
(if (= (count xs) 2) (if (= (length xs) 2)
(if (list? (last xs)) (if (list? (last xs))
(cons (caadr xs) (cons (caadr xs)
(cons (car xs) (cons (car xs)
@ -153,7 +153,7 @@
(list (last xs) (thread-first-internal (all-but-last xs)))))) (list (last xs) (thread-first-internal (all-but-last xs))))))
(defdynamic thread-last-internal [xs] (defdynamic thread-last-internal [xs]
(if (= (count xs) 2) (if (= (length xs) 2)
(if (list? (last xs)) (if (list? (last xs))
(cons-last (car xs) (last xs)) (cons-last (car xs) (last xs))
(list (cadr xs) (car xs))) (list (cadr xs) (car xs)))
@ -194,9 +194,9 @@
())) ()))
(defdynamic use-all-fn [names] (defdynamic use-all-fn [names]
(if (= (count names) 0) (if (= (length names) 0)
(macro-error "Trying to call use-all without arguments") (macro-error "Trying to call use-all without arguments")
(if (= (count names) 1) (if (= (length names) 1)
(list (list 'use (car names))) (list (list 'use (car names)))
(cons (list 'use (car names)) (use-all-fn (cdr names))))));(use-all (cdr names)))))) (cons (list 'use (car names)) (use-all-fn (cdr names))))));(use-all (cdr names))))))
@ -228,11 +228,11 @@
(list 'while true (cons 'do forms))) (list 'while true (cons 'do forms)))
(defdynamic case-internal [name xs] (defdynamic case-internal [name xs]
(if (= (count xs) 0) (if (= (length xs) 0)
(list) (list)
(if (= (count xs) 2) (if (= (length xs) 2)
(macro-error "case has even number of branches; add an else branch") (macro-error "case has even number of branches; add an else branch")
(if (= (count xs) 1) (if (= (length xs) 1)
(car xs) (car xs)
(list 'if (list 'if
(list '= name (car xs)) (list '= name (car xs))
@ -243,9 +243,9 @@
(case-internal name forms)) (case-internal name forms))
(defdynamic build-vararg [fn forms] (defdynamic build-vararg [fn forms]
(if (= (count forms) 0) (if (= (length forms) 0)
(macro-error "vararg macro needs at least one argument") (macro-error "vararg macro needs at least one argument")
(if (= (count forms) 1) (if (= (length forms) 1)
(car forms) (car forms)
(list fn (car forms) (build-vararg fn (cdr forms)))))) (list fn (car forms) (build-vararg fn (cdr forms))))))
@ -256,9 +256,9 @@
(build-vararg 'or forms)) (build-vararg 'or forms))
(defdynamic build-str* [forms] (defdynamic build-str* [forms]
(if (= (count forms) 0) (if (= (length forms) 0)
(list "") (list "")
(if (= (count forms) 1) (if (= (length forms) 1)
(list 'str (car forms)) (list 'str (car forms))
(list 'StringCopy.append (list 'str (car forms)) (build-str* (cdr forms)))))) (list 'StringCopy.append (list 'str (car forms)) (build-str* (cdr forms))))))

View File

@ -18,21 +18,21 @@
]) ])
(defn sum [data] (defn sum [data]
(if (= 0 (Array.count data)) (if (= 0 (Array.length data))
0.0 0.0
(let [total @(Array.nth data 0)] (let [total @(Array.nth data 0)]
(do (do
(for [i 1 (Array.count data)] (for [i 1 (Array.length data)]
(set! total (+ total @(Array.nth data i)))) (set! total (+ total @(Array.nth data i))))
total)))) total))))
(defn mean [data] (defn mean [data]
(/ (Statistics.sum data) (from-int (Array.count data)))) (/ (Statistics.sum data) (from-int (Array.length data))))
(defn _pp [a mean] (defn _pp [a mean]
(let [sum 0.0] (let [sum 0.0]
(do (do
(for [i 0 (Array.count a)] (for [i 0 (Array.length a)]
(let [tmp (Double.- (Double.copy (Array.nth a i)) mean)] (let [tmp (Double.- (Double.copy (Array.nth a i)) mean)]
(set! sum (Double.* tmp tmp)))) (set! sum (Double.* tmp tmp))))
sum))) sum)))
@ -40,7 +40,7 @@
(defn _xx [a mean] (defn _xx [a mean]
(let [sum 0.0] (let [sum 0.0]
(do (do
(for [i 0 (Array.count a)] (for [i 0 (Array.length a)]
(set! sum (Double.- (Double.copy (Array.nth a i)) mean))) (set! sum (Double.- (Double.copy (Array.nth a i)) mean)))
sum))) sum)))
@ -49,10 +49,10 @@
tmp (_xx data m)] tmp (_xx data m)]
(Double.- (_pp data m) (Double.- (_pp data m)
(Double./ (Double.* tmp tmp) (Double./ (Double.* tmp tmp)
(Double.from-int (Array.count data)))))) (Double.from-int (Array.length data))))))
(defn median [data] (defn median [data]
(let [n (Array.count data) (let [n (Array.length data)
sorted (Array.sort @data)] sorted (Array.sort @data)]
(cond (= n 0) 0.0 (cond (= n 0) 0.0
(= (mod n 2) 1) @(Array.nth data (/ n 2)) (= (mod n 2) 1) @(Array.nth data (/ n 2))
@ -62,21 +62,21 @@
2.0))))) 2.0)))))
(defn low-median [data] (defn low-median [data]
(let [n (Array.count data) (let [n (Array.length data)
sorted (Array.sort @data)] sorted (Array.sort @data)]
(cond (= n 0) 0.0 (cond (= n 0) 0.0
(= (mod n 2) 1) @(Array.nth data (/ n 2)) (= (mod n 2) 1) @(Array.nth data (/ n 2))
@(Array.nth data (dec (/ n 2)))))) ; else @(Array.nth data (dec (/ n 2)))))) ; else
(defn high-median [data] (defn high-median [data]
(let [n (Array.count data) (let [n (Array.length data)
sorted (Array.sort @data)] sorted (Array.sort @data)]
(if (= n 0) (if (= n 0)
0.0 0.0
@(Array.nth data (/ n 2))))) @(Array.nth data (/ n 2)))))
(defn grouped-median [data interval] (defn grouped-median [data interval]
(let [n (Array.count data) (let [n (Array.length data)
sorted (Array.sort @data)] sorted (Array.sort @data)]
(cond (= n 0) 0.0 (cond (= n 0) 0.0
(= n 1) @(Array.nth data 0) (= n 1) @(Array.nth data 0)
@ -88,12 +88,12 @@
(from-int f))))))) (from-int f)))))))
(defn variance [data] (defn variance [data]
(let [n (Array.count data) (let [n (Array.length data)
ss (_ss data)] ss (_ss data)]
(/ ss (from-int (dec n))))) (/ ss (from-int (dec n)))))
(defn pvariance [data] (defn pvariance [data]
(let [n (Array.count data) (let [n (Array.length data)
ss (_ss data)] ss (_ss data)]
(/ ss (from-int n)))) (/ ss (from-int n))))
@ -109,10 +109,10 @@
(defn median-abs-dev [data] (defn median-abs-dev [data]
(let [med (median data) (let [med (median data)
zero 0.0 zero 0.0
abs-devs (Array.replicate (Array.count data) &zero) abs-devs (Array.replicate (Array.length data) &zero)
n 1.4826] ; taken from Rust and R, because thats how its done apparently n 1.4826] ; taken from Rust and R, because thats how its done apparently
(do (do
(for [i 0 (Array.count data)] (for [i 0 (Array.length data)]
(Array.aset! &abs-devs i (abs (- med @(Array.nth data i))))) (Array.aset! &abs-devs i (abs (- med @(Array.nth data i)))))
(* (median &abs-devs) n)))) (* (median &abs-devs) n))))
@ -121,12 +121,12 @@
(defn percentile-of-sorted [sorted pct] (defn percentile-of-sorted [sorted pct]
(cond (cond
(Int.= 0 (Array.count sorted)) -1.0 ; should abort here (Int.= 0 (Array.length sorted)) -1.0 ; should abort here
(Double.< pct 0.0) -1.0 ; should abort here (Double.< pct 0.0) -1.0 ; should abort here
(Double.> pct 100.0) -1.0 ; should abort here (Double.> pct 100.0) -1.0 ; should abort here
(Int.= 1 (Array.count sorted)) @(Array.nth sorted 0) (Int.= 1 (Array.length sorted)) @(Array.nth sorted 0)
(Double.= 100.0 pct) @(Array.nth sorted (Int.dec (Array.count sorted))) (Double.= 100.0 pct) @(Array.nth sorted (Int.dec (Array.length sorted)))
(let [len (Int.dec (Array.count sorted)) (let [len (Int.dec (Array.length sorted))
rank (Double.* (Double./ pct 100.0) (Double.from-int len)) rank (Double.* (Double./ pct 100.0) (Double.from-int len))
lrank (Double.floor rank) lrank (Double.floor rank)
d (Double.- rank lrank) d (Double.- rank lrank)
@ -154,7 +154,7 @@
lo (Statistics.percentile-of-sorted tmp pct) lo (Statistics.percentile-of-sorted tmp pct)
hi (Statistics.percentile-of-sorted tmp (Double.- 100.0 pct))] hi (Statistics.percentile-of-sorted tmp (Double.- 100.0 pct))]
(do (do
(for [i 0 (Array.count tmp)] (for [i 0 (Array.length tmp)]
(let [samp @(Array.nth tmp i)] (let [samp @(Array.nth tmp i)]
(cond (cond
(> samp hi) (Array.aset! tmp i hi) (> samp hi) (Array.aset! tmp i hi)

View File

@ -6,7 +6,7 @@
(register append (Fn [&String &String] String)) (register append (Fn [&String &String] String))
(register delete (Fn [String] ())) (register delete (Fn [String] ()))
(register copy (Fn [&String] String)) (register copy (Fn [&String] String))
(register count (Fn [&String] Int)) (register length (Fn [&String] Int))
(register cstr (Fn [&String] (Ptr Char))) (register cstr (Fn [&String] (Ptr Char)))
(register str (Fn [&String] String)) (register str (Fn [&String] String))
(register prn (Fn [&String] String)) (register prn (Fn [&String] String))
@ -37,17 +37,17 @@
str))) str)))
(defn pad-left [len pad s] (defn pad-left [len pad s]
(let [x (Int.max 0 (- len (count s)))] (let [x (Int.max 0 (- len (length s)))]
(append &(from-chars &(Array.replicate x &pad)) s))) (append &(from-chars &(Array.replicate x &pad)) s)))
(defn pad-right [len pad s] (defn pad-right [len pad s]
(let [x (Int.max 0 (- len (count s)))] (let [x (Int.max 0 (- len (length s)))]
(append s &(from-chars &(Array.replicate x &pad))))) (append s &(from-chars &(Array.replicate x &pad)))))
(doc count-char "Returns the number of occurrences of `c` in the string `s`.") (doc count-char "Returns the number of occurrences of `c` in the string `s`.")
(defn count-char [s c] (defn count-char [s c]
(let-do [n 0] (let-do [n 0]
(for [i 0 (count s)] (for [i 0 (length s)]
(when (= c (char-at s i)) (when (= c (char-at s i))
(set! n (Int.inc n)))) (set! n (Int.inc n))))
n)) n))
@ -58,7 +58,7 @@
(doc empty? "Check if the string is the empty string.") (doc empty? "Check if the string is the empty string.")
(defn empty? [s] (defn empty? [s]
(Int.= (count s) 0)) (Int.= (length s) 0))
(defn substring [s a b] (defn substring [s a b]
(from-chars &(Array.subarray &(chars s) a b))) (from-chars &(Array.subarray &(chars s) a b)))
@ -73,35 +73,35 @@
(doc starts-with? "Check if the string `s` begins with the string `sub`.") (doc starts-with? "Check if the string `s` begins with the string `sub`.")
(defn starts-with? [s sub] (defn starts-with? [s sub]
(= sub &(prefix-string s (count sub)))) (= sub &(prefix-string s (length sub))))
(doc starts-with? "Check if the string `s` ends with the string `sub`.") (doc starts-with? "Check if the string `s` ends with the string `sub`.")
(defn ends-with? [s sub] (defn ends-with? [s sub]
(= sub &(suffix-string s (- (count s) (count sub))))) (= sub &(suffix-string s (- (length s) (length sub)))))
(doc zero "The empty string.") (doc zero "The empty string.")
(defn zero [] @"") (defn zero [] @"")
(doc sum-count "Returns the sum of counts from an array of Strings.") (doc sum-length "Returns the sum of lengths from an array of Strings.")
(defn sum-count [strings] (defn sum-length [strings]
(let-do [sum 0 (let-do [sum 0
lstrings (Array.count strings)] lstrings (Array.length strings)]
(for [i 0 lstrings] (for [i 0 lstrings]
(set! sum (+ sum (String.count (Array.nth strings i))))) (set! sum (+ sum (String.length (Array.nth strings i)))))
sum)) sum))
(doc concat "Returns a new string which is the concatenation of the provided `strings`.") (doc concat "Returns a new string which is the concatenation of the provided `strings`.")
(defn concat [strings] (defn concat [strings]
;; This is using a StringBuilder pattern to only perform one allocation and ;; This is using a StringBuilder pattern to only perform one allocation and
;; to only copy each of the incoming strings once. ;; to only copy each of the incoming strings once.
;; This currently performs wasted String.count calls, as we call it for each ;; This currently performs wasted String.length calls, as we call it for each
;; string once here and once in sum-count. ;; string once here and once in sum-length.
(let-do [j 0 (let-do [j 0
lstrings (Array.count strings) lstrings (Array.length strings)
result (String.allocate (sum-count strings) \ )] result (String.allocate (sum-length strings) \ )]
(for [i 0 lstrings] (for [i 0 lstrings]
(let-do [str (Array.nth strings i) (let-do [str (Array.nth strings i)
len (String.count str)] len (String.length str)]
(string-set-at! &result j str) (string-set-at! &result j str)
(set! j (+ j len)))) (set! j (+ j len))))
result)) result))
@ -109,14 +109,14 @@
(doc join "Returns a new string which is the concatenation of the provided `strings` separated by string `sep`.") (doc join "Returns a new string which is the concatenation of the provided `strings` separated by string `sep`.")
(defn join [sep strings] (defn join [sep strings]
(let-do [j 0 (let-do [j 0
lstrings (Array.count strings) lstrings (Array.length strings)
num-seps (- lstrings 1) num-seps (- lstrings 1)
sep-length (String.count &sep) sep-length (String.length &sep)
seps-size (* num-seps sep-length) seps-size (* num-seps sep-length)
result (String.allocate (+ seps-size (sum-count strings)) \ )] result (String.allocate (+ seps-size (sum-length strings)) \ )]
(for [i 0 lstrings] (for [i 0 lstrings]
(let-do [str (Array.nth strings i) (let-do [str (Array.nth strings i)
len (String.count str)] len (String.length str)]
(when (> i 0) (when (> i 0)
(do (do
(string-set-at! &result j &sep) (string-set-at! &result j &sep)
@ -129,12 +129,12 @@
(defn join-with-char [sep strings] (defn join-with-char [sep strings]
;; (= (join-with-char \ ["Hello" "world"]) (join " " ["Hello" "world"])) ;; (= (join-with-char \ ["Hello" "world"]) (join " " ["Hello" "world"]))
(let-do [j 0 (let-do [j 0
lstrings (Array.count strings) lstrings (Array.length strings)
sep-count (- lstrings 1) sep-length (- lstrings 1)
result (String.allocate (+ sep-count (sum-count strings)) \ )] result (String.allocate (+ sep-length (sum-length strings)) \ )]
(for [i 0 lstrings] (for [i 0 lstrings]
(let-do [str (Array.nth strings i) (let-do [str (Array.nth strings i)
len (String.count str)] len (String.length str)]
(when (> i 0) (when (> i 0)
(do (do
(string-set! &result j sep) (string-set! &result j sep)
@ -155,7 +155,7 @@
) )
(defdynamic string-join- [strs] (defdynamic string-join- [strs]
(if (= (count strs) 0) (if (= (length strs) 0)
'(String.copy "") '(String.copy "")
(list 'StringCopy.append (car strs) (string-join- (cdr strs))))) (list 'StringCopy.append (car strs) (string-join- (cdr strs)))))

View File

@ -24,7 +24,7 @@
[@"bg-cyan" @"46"] [@"bg-cyan" @"46"]
[@"bg-white" @"47"]]) [@"bg-white" @"47"]])
(def len-color-table (Array.count &color-table)) (def len-color-table (Array.length &color-table))
(defn color-name-to-ansi [cname] (defn color-name-to-ansi [cname]
(let [res @""] (let [res @""]
@ -103,7 +103,7 @@
) )
(defdynamic with-test-internal [name forms] (defdynamic with-test-internal [name forms]
(if (= (count forms) 1) (if (= (length forms) 1)
(list (list 'set! name (list 'ref (car forms)))) (list (list 'set! name (list 'ref (car forms))))
(cons (list 'set! name (list 'ref (car forms))) (cons (list 'set! name (list 'ref (car forms)))
(with-test-internal name (cdr forms))))) (with-test-internal name (cdr forms)))))

View File

@ -216,9 +216,9 @@
(defn zip- [f a b] (defn zip- [f a b]
(let [total []] (let [total []]
(do (do
(for [i 0 (Array.count a)] (for [i 0 (Array.length a)]
(set! total (Array.push-back @&total (f @(Array.nth a i) @(Array.nth b i))))) (set! total (Array.push-back @&total (f @(Array.nth a i) @(Array.nth b i)))))
(VN.init (Array.count a) total)))) (VN.init (Array.length a) total))))
(defn zip [f a b] (defn zip [f a b]
(if (= @(VN.n a) @(VN.n b)) (if (= @(VN.n a) @(VN.n b))

View File

@ -104,7 +104,7 @@ String StringCopy_append(String a, String b) {
return buffer; return buffer;
} }
int String_count(String *s) { int String_length(String *s) {
return strlen(*s); return strlen(*s);
} }

View File

@ -127,7 +127,7 @@ you need to qualify it with the module name, like this: ```Float.cos```.
If there are several used modules that contain symbols with the same name, the type inferer will try to figure If there are several used modules that contain symbols with the same name, the type inferer will try to figure
out which one of the symbols you really mean (based on the types in your code). If it can't, it will display an error. out which one of the symbols you really mean (based on the types in your code). If it can't, it will display an error.
For example, both the module ```String``` and ```Array``` contain a function named 'count'. In the following code it's For example, both the module ```String``` and ```Array``` contain a function named 'length'. In the following code it's
possible to see that it's the array version that is needed, and that one will be called: possible to see that it's the array version that is needed, and that one will be called:
``` ```
@ -135,7 +135,7 @@ possible to see that it's the array version that is needed, and that one will be
(use Array) (use Array)
(defn f [] (defn f []
(count [1 2 3 4 5])) (length [1 2 3 4 5]))
``` ```
In the following example it's not possible to figure out which type is intended: In the following example it's not possible to figure out which type is intended:
@ -144,7 +144,7 @@ In the following example it's not possible to figure out which type is intended:
(use Array) (use Array)
(defn f [x] (defn f [x]
(count x)) (length x))
``` ```
Specifying the type solves this error: Specifying the type solves this error:
@ -153,7 +153,7 @@ Specifying the type solves this error:
(use Array) (use Array)
(defn f [x] (defn f [x]
(String.count x)) (String.length x))
``` ```
### Structs ### Structs

View File

@ -58,7 +58,7 @@ A simple piece of code:
(defn say-hi [text] (defn say-hi [text]
(while true (while true
(if (< (count &text) 10) (if (< (length &text) 10)
(println "Too short!") (println "Too short!")
(println &text)))) (println &text))))
``` ```
@ -69,7 +69,7 @@ void say_MINUS_hi(string text) {
bool _5 = true; bool _5 = true;
while (_5) { while (_5) {
string* _14 = &text; // ref string* _14 = &text; // ref
int _12 = String_count(_14); int _12 = String_length(_14);
bool _10 = Int__LT_(_12, 10); bool _10 = Int__LT_(_12, 10);
if (_10) { if (_10) {
string _19 = "Too short!"; string _19 = "Too short!";
@ -89,7 +89,7 @@ If-statements are kind of tricky in regards to memory management:
```clojure ```clojure
(defn say-what [text] (defn say-what [text]
(let [manage (copy &text)] (let [manage (copy &text)]
(if (< (count &text) 10) (if (< (length &text) 10)
(copy "Too short") (copy "Too short")
manage))) manage)))
``` ```
@ -105,7 +105,7 @@ string say_MINUS_what(string text) {
string manage = _9; string manage = _9;
string _13; string _13;
string* _19 = &text; // ref string* _19 = &text; // ref
int _17 = String_count(_19); int _17 = String_length(_19);
bool _15 = Int__LT_(_17, 10); bool _15 = Int__LT_(_17, 10);
if (_15) { if (_15) {
string _24 = "Too short"; string _24 = "Too short";

View File

@ -125,7 +125,7 @@
(println (refstr after))))) (println (refstr after)))))
(defn get-last-string [xs] ;; Should be generic preferably... (defn get-last-string [xs] ;; Should be generic preferably...
(let [i (dec (Array.count &xs))] (let [i (dec (Array.length &xs))]
(String.copy (Array.nth &xs i)))) (String.copy (Array.nth &xs i))))
(defn print-last-string [] (defn print-last-string []
@ -179,11 +179,11 @@
)) ))
;; This used to be a bug becuase of multisym:s getting the same type variables: ;; This used to be a bug becuase of multisym:s getting the same type variables:
(defn two-counts-in-same-func [] (defn two-lengths-in-same-func []
(let [a [[1]] (let [a [[1]]
b [1 2 3] b [1 2 3]
c1 (count &a) c1 (length &a)
c2 (count &b)] c2 (length &b)]
(println* &(str (+ c1 c2))))) (println* &(str (+ c1 c2)))))
(defn changing-target-of-ref [] (defn changing-target-of-ref []
@ -226,6 +226,6 @@
(convert-struct-with-array-member-to-string) (convert-struct-with-array-member-to-string)
(threading) (threading)
(multiple-stringification-of-arrays) (multiple-stringification-of-arrays)
(two-counts-in-same-func) (two-lengths-in-same-func)
(changing-target-of-ref) (changing-target-of-ref)
)) ))

View File

@ -65,14 +65,14 @@
(defn energy [bodies] (defn energy [bodies]
(let-do [e 0.0] (let-do [e 0.0]
(for [i 0 (count bodies)] (for [i 0 (length bodies)]
(let-do [b (nth bodies i)] (let-do [b (nth bodies i)]
(set! e (+ e (* 0.5 (* (Planet.mass b) (set! e (+ e (* 0.5 (* (Planet.mass b)
(+ (ipow (Planet.vx b) 2) (+ (ipow (Planet.vx b) 2)
(+ (ipow (Planet.vy b) 2) (+ (ipow (Planet.vy b) 2)
(ipow (Planet.vz b) 2))))))) (ipow (Planet.vz b) 2)))))))
(for [j (+ i 1) (count bodies)] (for [j (+ i 1) (length bodies)]
(let [b2 (nth bodies j) (let [b2 (nth bodies j)
dx (- (Planet.x b) (Planet.x b2)) dx (- (Planet.x b) (Planet.x b2))
dy (- (Planet.y b) (Planet.y b2)) dy (- (Planet.y b) (Planet.y b2))
@ -91,9 +91,9 @@
(defn advance [bodies dt] (defn advance [bodies dt]
(do (do
(for [i 0 (count bodies)] (for [i 0 (length bodies)]
(let [b (nth bodies i)] (let [b (nth bodies i)]
(for [j (+ i 1) (count bodies)] (for [j (+ i 1) (length bodies)]
(let [b2 (nth bodies j) (let [b2 (nth bodies j)
dx (- (Planet.x b) (Planet.x b2)) dx (- (Planet.x b) (Planet.x b2))
dy (- (Planet.y b) (Planet.y b2)) dy (- (Planet.y b) (Planet.y b2))
@ -109,7 +109,7 @@
(Planet.set-vy! b2 (+ (Planet.vy b2) (* dy (* (Planet.mass b) mag)))) (Planet.set-vy! b2 (+ (Planet.vy b2) (* dy (* (Planet.mass b) mag))))
(Planet.set-vz! b2 (+ (Planet.vz b2) (* dz (* (Planet.mass b) mag))))))))) (Planet.set-vz! b2 (+ (Planet.vz b2) (* dz (* (Planet.mass b) mag)))))))))
(for [i 0 (count bodies)] (for [i 0 (length bodies)]
(update-planet i bodies dt)))) (update-planet i bodies dt))))
; defining bodies outside main (`def`) results in c compile error: ; defining bodies outside main (`def`) results in c compile error:

View File

@ -41,7 +41,7 @@
(SDL.rect (* x 2) 80 16 16) (SDL.rect (* x 2) 80 16 16)
(SDL.rect (* x 4) 112 16 16) (SDL.rect (* x 4) 112 16 16)
(SDL.rect (* x 8) 144 16 16)] (SDL.rect (* x 8) 144 16 16)]
n (count &rects)] n (length &rects)]
(SDL.render-fill-rects rend (raw rects) n)) (SDL.render-fill-rects rend (raw rects) n))
(SDL.set-render-draw-color rend 255 50 100 255) (SDL.set-render-draw-color rend 255 50 100 255)
(for [x 0 512 16] (for [x 0 512 16]
@ -50,7 +50,7 @@
(SDL.render-draw-line rend 512 (+ 256 (/ x 2)) 0 512))) (SDL.render-draw-line rend 512 (+ 256 (/ x 2)) 0 512)))
(SDL.set-render-draw-color rend 0 0 0 255) (SDL.set-render-draw-color rend 0 0 0 255)
(let [lines (random-lines) (let [lines (random-lines)
n (count &lines)] n (length &lines)]
(SDL.render-draw-lines rend (raw lines) n)) (SDL.render-draw-lines rend (raw lines) n))
(let [img @(Images.img1 &images)] (let [img @(Images.img1 &images)]
(SDL.render-copy-ex rend (SDL.render-copy-ex rend

View File

@ -15,7 +15,7 @@
(defn lookup [bucket lookup-key] (defn lookup [bucket lookup-key]
(let-do [pairs (Bucket.entries bucket) (let-do [pairs (Bucket.entries bucket)
result (zero)] result (zero)]
(for [i 0 (count pairs)] (for [i 0 (length pairs)]
(let [pair (nth pairs i)] (let [pair (nth pairs i)]
(when (= (Entry.key pair) &lookup-key) (when (= (Entry.key pair) &lookup-key)
(set! result @(Entry.value pair))))) (set! result @(Entry.value pair)))))

View File

@ -84,7 +84,7 @@
g h i])))) g h i]))))
(defn tick [world newWorld] (defn tick [world newWorld]
(for [i 0 (count world)] (for [i 0 (length world)]
(let [x (mod i height) (let [x (mod i height)
y (/ i width) y (/ i width)
total (neighbours world x y) total (neighbours world x y)

View File

@ -29,17 +29,17 @@
(def grid-size 32) (def grid-size 32)
(defn draw-snake [rend snake] (defn draw-snake [rend snake]
(let [body-count (count (body snake))] (let [body-length (length (body snake))]
(for [i 0 body-count] (for [i 0 body-length]
(let [part (nth (body snake) i) (let [part (nth (body snake) i)
x (* grid-size (to-int @(Vector2.V2.x part))) x (* grid-size (to-int @(Vector2.V2.x part)))
y (* grid-size (to-int @(Vector2.V2.y part)))] y (* grid-size (to-int @(Vector2.V2.y part)))]
(if (= i 0) (if (= i 0)
(do (do
(SDL.set-render-draw-color rend 200 255 (+ 100 (* body-count 10)) 255) (SDL.set-render-draw-color rend 200 255 (+ 100 (* body-length 10)) 255)
(SDL.render-fill-rect rend (address (SDL.rect x y grid-size grid-size)))) (SDL.render-fill-rect rend (address (SDL.rect x y grid-size grid-size))))
(do (do
(SDL.set-render-draw-color rend 200 (+ 50 (* i (/ 200 body-count))) 100 255) (SDL.set-render-draw-color rend 200 (+ 50 (* i (/ 200 body-length))) 100 255)
(SDL.render-fill-rect rend (address (SDL.rect x y grid-size grid-size))))))))) (SDL.render-fill-rect rend (address (SDL.rect x y grid-size grid-size)))))))))
(defn draw-human [rend human] (defn draw-human [rend human]
@ -89,7 +89,7 @@
(defn shift-body [body] (defn shift-body [body]
(do (do
(let [i (- (Array.count body) 2)] (let [i (- (Array.length body) 2)]
(while (> i -1) (while (> i -1)
(do (do
(aset! body (inc i) @(nth body i)) (aset! body (inc i) @(nth body i))

View File

@ -6,6 +6,6 @@
(defn main [] (defn main []
(with-test test (with-test test
(assert-equal test 1 2 "1 == 2") (assert-equal test 1 2 "1 == 2")
(assert-true test (Int.> (Array.count &[1 2 3]) 1) "len([1 2 3]) == 1") (assert-true test (Int.> (Array.length &[1 2 3]) 1) "len([1 2 3]) == 1")
(assert-not-equal test "hi" "bye" "hi != bye") (assert-not-equal test "hi" "bye" "hi != bye")
(print-test-results test))) (print-test-results test)))

View File

@ -239,9 +239,9 @@ templateAsetUninitializedBang = defineTypeParameterizedTemplate templateCreator
,"}"])) ,"}"]))
(const []) (const [])
templateCount :: (String, Binder) templateLength :: (String, Binder)
templateCount = defineTypeParameterizedTemplate templateCreator path t templateLength = defineTypeParameterizedTemplate templateCreator path t
where path = (SymPath ["Array"] "count") where path = (SymPath ["Array"] "length")
t = (FuncTy [RefTy (StructTy "Array" [VarTy "t"])] IntTy) t = (FuncTy [RefTy (StructTy "Array" [VarTy "t"])] IntTy)
templateCreator = TemplateCreator $ templateCreator = TemplateCreator $
\typeEnv env -> \typeEnv env ->

View File

@ -438,12 +438,12 @@ commandIsSymbol [x] =
XObj (Sym _ _) _ _ -> return (Right trueXObj) XObj (Sym _ _) _ _ -> return (Right trueXObj)
_ -> return (Right falseXObj) _ -> return (Right falseXObj)
commandCount :: CommandCallback commandLength :: CommandCallback
commandCount [x] = commandLength [x] =
case x of case x of
XObj (Lst lst) _ _ -> return (Right (XObj (Num IntTy (fromIntegral (length lst))) Nothing Nothing)) XObj (Lst lst) _ _ -> return (Right (XObj (Num IntTy (fromIntegral (length lst))) Nothing Nothing))
XObj (Arr arr) _ _ -> return (Right (XObj (Num IntTy (fromIntegral (length arr))) Nothing Nothing)) XObj (Arr arr) _ _ -> return (Right (XObj (Num IntTy (fromIntegral (length arr))) Nothing Nothing))
_ -> return (Left (EvalError ("Applying 'count' to non-list: " ++ pretty x ++ " at " ++ prettyInfoFromXObj x))) _ -> return (Left (EvalError ("Applying 'length' to non-list: " ++ pretty x ++ " at " ++ prettyInfoFromXObj x)))
commandCar :: CommandCallback commandCar :: CommandCallback
commandCar [x] = commandCar [x] =
@ -597,13 +597,13 @@ commandSubstring [a, b, c] =
_ -> _ ->
Left (EvalError ("Can't call substring with " ++ pretty a ++ ", " ++ pretty b ++ " and " ++ pretty c)) Left (EvalError ("Can't call substring with " ++ pretty a ++ ", " ++ pretty b ++ " and " ++ pretty c))
commandStringCount :: CommandCallback commandStringLength :: CommandCallback
commandStringCount [a] = commandStringLength [a] =
return $ case a of return $ case a of
XObj (Str s) _ _ -> XObj (Str s) _ _ ->
Right (XObj (Num IntTy (fromIntegral (length s))) (Just dummyInfo) (Just IntTy)) Right (XObj (Num IntTy (fromIntegral (length s))) (Just dummyInfo) (Just IntTy))
_ -> _ ->
Left (EvalError ("Can't call count with " ++ pretty a)) Left (EvalError ("Can't call length with " ++ pretty a))
commandStringJoin :: CommandCallback commandStringJoin :: CommandCallback
commandStringJoin [a] = commandStringJoin [a] =

View File

@ -45,7 +45,7 @@ arrayModule = Env { envBindings = bindings, envParent = Nothing, envModuleName =
, templateAset , templateAset
, templateAsetBang , templateAsetBang
, templateAsetUninitializedBang , templateAsetUninitializedBang
, templateCount , templateLength
, templatePushBack , templatePushBack
, templatePopBack , templatePopBack
, templateDeleteArray , templateDeleteArray
@ -156,7 +156,7 @@ dynamicModule = Env { envBindings = bindings, envParent = Nothing, envModuleName
[ addCommand "list?" 1 commandIsList [ addCommand "list?" 1 commandIsList
, addCommand "array?" 1 commandIsArray , addCommand "array?" 1 commandIsArray
, addCommand "symbol?" 1 commandIsSymbol , addCommand "symbol?" 1 commandIsSymbol
, addCommand "count" 1 commandCount , addCommand "length" 1 commandLength
, addCommand "car" 1 commandCar , addCommand "car" 1 commandCar
, addCommand "cdr" 1 commandCdr , addCommand "cdr" 1 commandCdr
, addCommand "last" 1 commandLast , addCommand "last" 1 commandLast
@ -203,7 +203,7 @@ dynamicStringModule = Env { envBindings = bindings, envParent = Nothing, envModu
where bindings = Map.fromList [ addCommand "char-at" 2 commandCharAt where bindings = Map.fromList [ addCommand "char-at" 2 commandCharAt
, addCommand "index-of" 2 commandIndexOf , addCommand "index-of" 2 commandIndexOf
, addCommand "substring" 3 commandSubstring , addCommand "substring" 3 commandSubstring
, addCommand "count" 1 commandStringCount , addCommand "length" 1 commandStringLength
, addCommand "join" 1 commandStringJoin , addCommand "join" 1 commandStringJoin
, addCommand "directory" 1 commandStringDirectory , addCommand "directory" 1 commandStringDirectory
] ]

View File

@ -41,11 +41,11 @@
x))) x)))
(defn all-eq [a b] (defn all-eq [a b]
(if (/= (Array.count a) (Array.count b)) (if (/= (Array.length a) (Array.length b))
false false
(let [eq true] (let [eq true]
(do (do
(for [i 0 (Array.count a)] (for [i 0 (Array.length a)]
(if (/= @(Array.nth a i) @(Array.nth b i)) (if (/= @(Array.nth a i) @(Array.nth b i))
(set! eq false) (set! eq false)
())) ()))

View File

@ -279,11 +279,11 @@
;; TODO! Failing to compile this... ;; TODO! Failing to compile this...
;; (defmodule ArrayCompareExtension ;; (defmodule ArrayCompareExtension
;; (defn < [a b] ;; (defn < [a b]
;; (Int.< (Array.count a) ;; (Int.< (Array.length a)
;; (Array.count b))) ;; (Array.length b)))
;; (defn > [a b] ;; (defn > [a b]
;; (Int.> (Array.count a) ;; (Int.> (Array.length a)
;; (Array.count b)))) ;; (Array.length b))))
;; (defn array-sort-1 [] ;; (defn array-sort-1 []
;; (let [xs [[0 0] [0 0 0] [0 0 0 0] [0]] ;; (let [xs [[0 0] [0 0 0] [0 0 0 0] [0]]
;; ys (Array.sort xs)] ;; ys (Array.sort xs)]
@ -306,7 +306,7 @@
(defn array-copy-map-1 [] (defn array-copy-map-1 []
(let [xs [@"a" @"bb" @"ccc"] (let [xs [@"a" @"bb" @"ccc"]
ys (Array.copy-map String.count &xs)] ys (Array.copy-map String.length &xs)]
(assert (= &[1 2 3] &ys)))) (assert (= &[1 2 3] &ys))))
(defn str-ref [r] (defn str-ref [r]

View File

@ -4,22 +4,22 @@
(use-all Double Test Statistics) (use-all Double Test Statistics)
(defn all-eq [a b] (defn all-eq [a b]
(if (Int./= (Array.count a) (Array.count b)) (if (Int./= (Array.length a) (Array.length b))
false false
(let [res true] (let [res true]
(do (do
(for [i 0 (Array.count a)] (for [i 0 (Array.length a)]
(if (not (Double.= @(Array.nth a i) @(Array.nth b i))) (if (not (Double.= @(Array.nth a i) @(Array.nth b i)))
(set! res false) (set! res false)
())) ()))
res)))) res))))
(defn all-approx [a b] (defn all-approx [a b]
(if (Int./= (Array.count a) (Array.count b)) (if (Int./= (Array.length a) (Array.length b))
false false
(let [res true] (let [res true]
(do (do
(for [i 0 (Array.count a)] (for [i 0 (Array.length a)]
(if (not (Double.approx @(Array.nth a i) @(Array.nth b i))) (if (not (Double.approx @(Array.nth a i) @(Array.nth b i)))
(set! res false) (set! res false)
())) ()))

View File

@ -290,7 +290,7 @@
) )
(assert-equal test (assert-equal test
5 5
(count &(allocate 5 \a)) (length &(allocate 5 \a))
"allocate works correctly III" "allocate works correctly III"
) )
(assert-equal test (assert-equal test