Iteration

There are several iteration mechanisms in Lumen. The simplest is a while loop:

AخA
 
1
(let i 3
2
  (while (> i 0)
3
    (print (dec i))))

    

The shorthand for iterating from 0 to N is for:

2
 
1
(for i 3
2
  (print i))

    

You can enumerate the keys and values of a list with each:

x
 
1
(each (k v) (list 1 2 a: 10 b: 20)
2
  (print (cat k " " v)))
3
(each v (list 1 2 a: 10 b: 20) ; values only
4
  (print v))
5
(each (k (a b)) ; destructuring
6
  (list (list 10 20) bar: (list "a" "b"))
7
  (print (cat k " " a " " b)))
8

    

each will bind keys and values in any order. If you want only the positional values of a list, you can enumerate them in order using step:

5
 
1
(step x (list 1 2 3)
2
  (print x))
3
(step (a b) (list (list 1 2) (list 10 20)) ; destructuring
4
  (print a)
5
  (print b))