up previous next
 2.5.1 Introduction to LIST
A CoCoA list is a sequence of CoCoA objects between square brackets. See also List Constructors. The objects may be of different types, though a well-designed algorithm will likely create lists of objects of a single type.

In particular, a list may contain other lists. The empty list is [] . We use square brackets to index into a list. If L is a non-empty list and N is an integer (between 1 and len(L) ), then L[N] is the N -th component of L ; indexes start from 1.

If L contains sublists, we can write L[N_1, N_2,...,N_s] as shorthand for L[N_1][N_2]...[N_s] (see the example below).

Lists are often used to build structured objects of type MAT , MODULEELEM , IDEAL , and MODULE .

 Example
 ```/**/ use R ::= QQ[t,x,y,z]; /**/ L := [34*x+y^2, "a string", [], [True, False]]; -- a list /**/ L; -- the 1st component y^2 +34*x /**/ L; a string /**/ L; [ ] /**/ L; -- The 4th component is a list, itself; [true, false] /**/ L; -- its 1st component; true /**/ L[4,1]; -- the same. true /**/ [1,"a"]+[2,"b"]; -- NOTE: one may add lists if their components [3, "ab"] -- are compatible (see "Algebraic Operators"). /**/ L := [x^2-y, t*y^2-z^3]; /**/ I := ideal(L); /**/ I; ideal(x^2 -y, t*y^2 -z^3) ```