27.2 List

List( obj )
List( list, func )

In its first form List returns the argument obj, which must be a list, a permutation, a string or a word, converted into a list. If obj is a list, it is simply returned. If obj is a permutation, List returns a list where the i-th element is the image of i under the permutation obj. If obj is a word, List returns a list where the i-th element is the i-th generator of the word, as a word of length 1.

    gap> List( [1,2,3] );
    [ 1, 2, 3 ]
    gap> List( (1,2)(3,4,5) );
    [ 2, 1, 4, 5, 3 ] 

In its second form List returns a new list, where each element is the result of applying the function func, which must take exactly one argument and handle the elements of list, to the corresponding element of the list list. The list list must not contain holes.

    gap> List( [1,2,3], x->x^2 );
    [ 1, 4, 9 ]
    gap> List( [1..10], IsPrime );
    [ false, true, true, false, true, false, true, false, false, false ]

Note that this function is called map in Lisp and many other similar programming languages. This name violates the GAP rule that verbs are used for functions that change their arguments. According to this rule map would change list, replacing every element with the result of the application func to this argument.

Previous Up Top Next
Index

GAP 3.4.4
April 1997