|
![]() |
||||||||||||||
List TutorialList FunctionsBasic List functions are empty : (List['1] -> Bool) length : (List['1] -> Integer) hd : (List['1] -> '1) tl : (List['1] -> List['1]) subList : (List['1] * Integer * Integer -> List['1]) These functions are applicable to lists with any element type. Function length(l) computes the length of the list. Function empty(l) tests if the list is empty. A list is considered empty if its length is zero. Function hd(l) computes the first element of the list. It is not defined on empty lists. Function tl(l) computes a tail of the given list. The list tail is a list consisting of all list elements except the first one, in the same order. It is not defined on empty lists. Infix binary operator h:l constructs a list having head h and tail t. The operator type is ('1 * List['1] -> List['1]). Function subList(l,p,n) computes a sublist of the given list, beginning at position p and contains n elements. If the list length is less than p+n, the sublist will contain only length(l)-p elements. If the list length is less than p+1, the sublist will be empty. Source code:{# empty([]), empty([1,2,3]), length([1,2,3]), hd([1,2,3]), tl([1,2,3]), subList([1,2,3,4,5,6],1,3), 1:[2,3], 1:2:3:nil #} Result:{# true, false, 3, 1, [2,3], [2,3,4], [1,2,3], [1,2,3] #}
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||