1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| -- Assuming the following are primitive: random, tl, hd, null, nil, id, apply, acc, `, cons, and rng
-- drops the first occurrence of a value that is true for the given predicate
def drop-first null -> {} ; [1, 2 hd] ap -> tl ; [2 hd, [id, tl] drop-first]
-- selects a random element
def rsel [random, id] acc
-- selects an element and drops it
def select [rsel, id] [1, [[1, ^id] eq, 2] drop-first]
-- is equal to zero
def eq0 [id, 0] eq
-- subtracts by one
def decr [id, 1] -
def bag [50, {}, {1..10}] iter
where iter 1 eq0 -> 2
2 null -> [1, 2, {1..10}] iter
; [1, 2, 3 sel] [1 decr, [2, 3 1] cons, 3 2] iter |