1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-10 15:40:30 +00:00

Merge branch 'master' into compile-opt

This commit is contained in:
Calvin Rose 2023-08-07 09:40:27 -05:00
commit 43ab06467f

View File

@ -1450,12 +1450,10 @@
a new array. If a string or buffer is provided, returns an array of its a new array. If a string or buffer is provided, returns an array of its
byte values, reversed.` byte values, reversed.`
[t] [t]
(def len (length t)) (var n (length t))
(var n (- len 1)) (def ret (array/new-filled n))
(def ret (array/new len)) (forv i 0 n
(while (>= n 0) (put ret i (in t (-- n))))
(array/push ret (in t n))
(-- n))
ret) ret)
(defn invert (defn invert
@ -1566,31 +1564,31 @@
(defn keys (defn keys
"Get the keys of an associative data structure." "Get the keys of an associative data structure."
[x] [x]
(def arr @[]) (def arr (array/new-filled (length x)))
(var k (next x nil)) (var i 0)
(while (not= nil k) (eachk k x
(array/push arr k) (put arr i k)
(set k (next x k))) (++ i))
arr) arr)
(defn values (defn values
"Get the values of an associative data structure." "Get the values of an associative data structure."
[x] [x]
(def arr @[]) (def arr (array/new-filled (length x)))
(var k (next x nil)) (var i 0)
(while (not= nil k) (each v x
(array/push arr (in x k)) (put arr i v)
(set k (next x k))) (++ i))
arr) arr)
(defn pairs (defn pairs
"Get the key-value pairs of an associative data structure." "Get the key-value pairs of an associative data structure."
[x] [x]
(def arr @[]) (def arr (array/new-filled (length x)))
(var k (next x nil)) (var i 0)
(while (not= nil k) (eachp p x
(array/push arr (tuple k (in x k))) (put arr i p)
(set k (next x k))) (++ i))
arr) arr)
(defn frequencies (defn frequencies