next up previous contents
Next: Simple Output Up: Built-in Functions for Sets, Previous: The op Operator

The length Function

The length operator accepts a set, list or string as a parameter and returns the length of the object.

> numbers := [1, {2, 3}, [4, {5, 6}]];      # a list with 3 elements
> length(numbers);                          # 1st -> 1
                                            # 2nd -> {2,3} 
                                            # 3rd -> [4, {5, 6}]
3
> length('I have length 16');               # a string
16
We can use length function to remove the last element of a list.
> length(weekdays);
5
> shortweek := weekdays[1..length(weekdays)-1];   # taking Friday off
shortweek := [monday, tuesday, wednesday, thursday]



Gaston Gonnet
1998-09-15