grino/examples/array.gri

31 lines
552 B
Plaintext

($ a [1 true 2])
(assert= 1 (ref a 0))
(assert= true (ref a 1))
(assert= 2 (ref a 2))
($ b [[2 4 6] [8 10 12] [14 16 18]])
(assert= 12 (ref b 1 2))
(assert= true (empty? []))
(assert= false (empty? [1]))
(assert= 7 (head [7 3 1]))
(assert= 3 (ref (tail [7 3 1]) 0))
(assert= 1 (ref (tail [7 3 1]) 1))
($ (c arr)
(if (empty? arr)
0
(+ (head arr) (c (tail arr)))))
(assert= 13 (c [2 4 6 1]))
($ d (cons 2 (cons 4 [6])))
(assert= 2 (ref d 0))
(assert= 4 (ref d 1))
(assert= 6 (ref d 2))
(assert= 3 (len d))
(assert= 4 (len (cons 18 d)))