scan(L, f) applies the function f to each element of the list L. The function values are discarded.
i1 : scan({a, 4, "George", 2^100}, print)
a
4
George
1267650600228229401496703205376
|
scan(n, f) applies the function f to each element of the list 0, 1, ..., n-1
i2 : scan(4, print) 0 1 2 3 |
i3 : v = {a,b,c}; scan(#v, i -> print(i,v#i))
(0, a)
(1, b)
(2, c)
|
The keyword break can be used to terminate the scan prematurely, and optionally to specify a return value for the expression. Here we use it to locate the first even number in a list.
i5 : scan({3,5,7,11,44,55,77}, i -> if even i then break i)
o5 = 44
|
The object scan is a compiled function.