27.24 Number

Number( list )
Number( list, func )

In the first form Number returns the number of bound entries in the list list.

For lists that contain no holes Number, Length (see Length), and Size (see Size) return the same value. For lists with holes Number returns the number of bound entries, Length returns the largest index of a bound entry, and Size signals an error.

Number returns the number of elements of the list list for which the unary function func returns true. If an element for which func returns true appears several times in list it will also be counted several times. func must return either true or false for every element of list, otherwise an error is signalled.

    gap> Number( [ 2, 3, 5, 7 ] );
    4
    gap> Number( [, 2, 3,, 5,, 7,,,, 11 ] );
    5
    gap> Number( [1..20], IsPrime );
    8
    gap> Number( [ 1, 3, 4, -4, 4, 7, 10, 6 ], IsPrimePowerInt );
    4
    gap> Number( [ 1, 3, 4, -4, 4, 7, 10, 6 ],
    >            n -> IsPrimePowerInt(n) and n mod 2 <> 0 );
    2 
Filtered (see Filtered) allows you to extract the elements of a list that have a certain property.

Previous Up Top Next
Index

GAP 3.4.4
April 1997