Remove length checks to a number of core functions.
This lets them be more generic and implemented over a wider range of
data types, such as fibers.
(defn true? "Check if x is true." [x] (= x true))
(defn false? "Check if x is false." [x] (= x false))
(defn nil? "Check if x is nil." [x] (= x nil))
-(defn empty? "Check if xs is empty." [xs] (= (length xs) 0))
+(defn empty? "Check if xs is empty." [xs] (= nil (next xs nil)))
# For macros, we define an imcomplete odd? function that will be overriden.
(defn odd? [x] (= 1 (mod x 2)))
Returns a new array.`
[f init ind]
(var res init)
- (def ret (array/new (length ind)))
+ (def ret @[])
(each x ind (array/push ret (set res (f res x))))
ret)
return value will be (length ind).`
[f ind]
(var k (next ind))
- (def ret (array/new (length ind)))
+ (def ret @[])
(if (= nil k) (break ret))
(var res (in ind k))
(array/push ret res)
(reduce fop x forms))
(defn- walk-ind [f form]
- (def len (length form))
- (def ret (array/new len))
+ (def ret @[])
(each x form (array/push ret (f x)))
ret)
(defn keys
"Get the keys of an associative data structure."
[x]
- (def arr (array/new (length x)))
+ (def arr @[])
(var k (next x nil))
(while (not= nil k)
(array/push arr k)
(defn values
"Get the values of an associative data structure."
[x]
- (def arr (array/new (length x)))
+ (def arr @[])
(var k (next x nil))
(while (not= nil k)
(array/push arr (in x k))
(defn pairs
"Get the key-value pairs of an associative data structure."
[x]
- (def arr (array/new (length x)))
+ (def arr @[])
(var k (next x nil))
(while (not= nil k)
(array/push arr (tuple k (in x k)))
`Takes a table or struct and returns and array of key value pairs
like @[k v k v ...]. Returns a new array.`
[dict]
- (def ret (array/new (* 2 (length dict))))
+ (def ret @[])
(loop [k :keys dict] (array/push ret k (in dict k)))
ret)
