Files
rust-mal/libs/lists.mal
teo3300 5db1cf1910 Small improvements in function definition
- Inline 'def! t' for filter
- Removed 'len'
2024-06-19 16:15:33 +09:00

16 lines
528 B
Plaintext

(def! concat (fn* [x y] (def! concat-r (fn* [x y t]
"Concatenate arguments, keeping their order"
(if (car x)
(concat-r (cdr x) y (cons (car x) t))
(if (car y)
(concat-r '() (cdr y) (cons (car y) t))
t))))
(concat-r (reverse y) (reverse x) '())))
(def! distribute (fn* [x] (def! distribute-r (fn* [p n t]
(if (empty? n)
t
(let* [c (car n) n (cdr n)]
(distribute-r (cons c p) n (cons (cons c (concat p n)) t))))))
(distribute-r '() x '())))