Previous Up Next

6.1.7  Finding a subsequence or a sublist

The bracket notation used to find elements of sequences and lists can also be used to extract a range of elements. If S is a sequence or list of size n, then S[n1..n2] returns the subsequence or sublist of S consisting of the elements with indices from n1 to n2, where 0 ≤ n1n2 < s (in Xcas syntax mode) or 0 < n1n2s in other syntax modes.

For lists, the at command can also be used to get a sublist.

Again, at cannot be used for sequences.

An alternative to using at for finding a sublist is the mid command, which again cannot be used for sequences.

Examples

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

1,2,3
          
(A,B,C,D,E)[1..3]
     
B,C,D           
at([1,2,3,4,5],2..4
     

3,4,5
          
mid([0,1,2,3,4,5],2,3)
     

2,3,4
          
mid([0,1,2,3,4,5],2)
     

2,3,4,5
          

Previous Up Next