first(s)
Return the first element of the sequence s. If s is not a valid sequence, return
false.
The related functions, second, third, fourth, fifth,
sixth, seventh, eighth, ninth and tenth
returns respectively the second, third, fourth, fifth, sixth, seventh, eighth, ninth, and tenth
elements of the sequence s, and returns false if s is not a valid sequence.
First, rest and count are generic functions
recognized by the language. A user-defined object can respond to these messages and start behaving like a sequence.
function ints(n) n:~ints(n + 1) // an infinite sequence of integers
let s = ints(0)
first(s)
// 0
second(s)
// 1
tenth(s)
// 9
// a custom sequence
function make_bag(xs)
let (len = array_length(xs))
^(msg)
| 'first -> when (len > 0) array_at(xs, 0)
| 'rest -> when (len > 1) make_bag(subarray(xs, 1, len))
| 'count -> len
let b = make_bag(#[10, 20, 30])
first(b)
// 10
nth(2, b)
// 30
count(b)
// 30