{Record
cons
fold
reduce
for_each
for_each_numbered
iota
map
filter
length
reverse
reverse_append
append
concat
concat_map
fetch
zip
unzip
last
join
repeat
}
Where
Let (cons head tail)
(head :: tail)
Let (map list transform)
(fold list [] Func elem list. ((transform elem) :: list))
Let (iota n)
For (consing 0)
Define (consing i)
If (i = n)
`nil
(i :: (consing (i + 1)))
Let (filter list pred)
(fold list [] Func elem list. If (pred elem) (elem :: list) list)
Let (length list)
(reduce list 0
Func count _. (count + 1))
Let (concat lists)
(fold lists [] append)
Let (concat_map list f)
(fold list []
Func item items. (append (f item) items))
Let (fetch list n)
If (n < 0)
`nothing
Iterate {list n} From {list n}
Match list
| `cons.{item list}
If (n = 0)
`just.item
Continue {list (n - 1)}
| `nil `nothing
;
Let (zip a b)
Iterate {a b z} From {a b []}
Match a
| `cons.{ai a}
Match b
| `cons.{bi b} Continue {a b ({ai bi} :: z)}
| `nil (reverse z)
;
| `nil (reverse z)
;
Let (unzip list)
(fold list {[] []}
Func {a b} {as bs}. {(a :: as) (b :: bs)})
Let (last items)
(reduce items `nothing Func _ item. `just.item)
Let (join glue lists)
(fold lists []
Func list lists.
Match lists
| `nil [list]
| `cons._ (list :: (glue :: lists))
;)
Define (repeat n elem)
If (n = 0) [] (elem :: (repeat (n - 1) elem))
Where
Let (append left right) (reverse_append (reverse left) right)
Where
Let (reverse list) (reverse_append list [])
Where
Let (reverse_append queue tail)
(reduce queue tail
Func list elem. (elem :: list))
Where
Let (fold list nil cons)
For (fold list)
Define (fold list)
Match list
| `nil nil
| `cons.{elem list} (cons elem (fold list))
;
Let (reduce list zero plus)
Iterate {list sum} From {list zero}
Match list
| `nil sum
| `cons.{elem list} Continue {list (plus sum elem)}
;
Let (for_each list command)
Iterate {list} From {list}
Match list
| `nil {}
| `cons.{elem list}
Do (command elem)
In
Continue {list}
;
Let (for_each_numbered list command)
Iterate {i list} From {0 list}
Match list
| `nil {}
| `cons.{elem list}
Do (command i elem)
In
Continue {(i + 1) list}
;