up previous next
Tutorial-05: creating lists
Tutorial-05 for CoCoA-5
A convenient way of "putting together" many values in CoCoA-5
is to put them into a LIST. Though the CoCoA-5 name is "LIST"
the data-structure more closely resembles a "vector" in C++
than a "list" in C++.
CoCoA-5 does not impose restrictions on the values a LIST may
contain; nevertheless it usually makes most sense if the values
are all of the same type (e.g. all integers, all polynomials).
A list may be created in several ways. The simplest is to write
out the entries explicitly. Another is to start with an empty list,
and the append new elements in a loop. There is also a convenient
syntax inspired by the mathematical notation for sets.
If you have a list, you can find out how many elements it contains
using the function
len
. You can also iterate over the
elements of a list using the
foreach
loop command.