Previous Up Next

2.37.2  Get an element or a sub-list of a list : at []

Get an element

The n-th element of a list l of size s is addressed by l[n] where n is in [0..s−1] or [1..s]. The equivalent prefixed function is at, which takes as argument a list and an integer n.
at returns the element of the list of index n.
Input :

[0,1,2][1]

or

at([0,1,2],1)

Output :

1

Extract a sub-list

If l is a list of size s, l[n1..n2] returns the list extracted from l containing the elements of indices n1 to n2 where 0 ≤ n1n2 < s (in Xcas syntax mode) or 0 < n1n2s in other syntax modes. The equivalent prefixed function is at with a list and an interval of integers (n1..n2) as arguments.
See also : mid, section 2.37.3.
Input :

[0,1,2,3,4][1..3]

or

at([0,1,2,3,4],1..3)

Output :

[1,2,3]

Warning
at can not be used for sequences, index notation must be used, like in (0,1,2,3,4,5)[2..3].


Previous Up Next