Name: Take - extract element sequences from a container

Synopsis:

array  n Take                  return the first n elements 
array -n Take                  return the last n elements 
array [n1 n2] Take             return elements n1 through n2 
array [n1 n2 s] Take           return elements n1 through n2 in steps of s 
array [[seq1]...[seqn]] Take   return a nested list in which elements 
specified by seqi are taken at level i in list. 
Operations are the same on strings. 
The implementation of Take uses the command container to abstract 
the container type. 
Note that Take handles indices ranging from -N to N where 
N is the length of the original container and asking for index 0 
will return an empty array. 
If the specified indices do not exist in the container, Take throws a RangeCheck error. 
If n2 &lt; n1, Take returns an empty container.


Examples:

[4 9 -7 3 2 11] 2 Take    --&gt; [4 9] 
[4 9 -7 3 2 11] -2 Take   --&gt; [2 11] 
[1 2 3 4 5] [-2] Take     --&gt; 4 
[1 2 3 4 5] [1 -2] Take   --&gt; [1 2 3 4] 
[1 2 3 4 5] [1 -2 2] Take --&gt; [1 3] 
[1 2 3 4 5] [1 -1 2] Take --&gt; [1 3 5] 
% [1 2 3 4 5] [1 6] Take    --&gt; [Error]: RangeCheck 
(HAL) {1 add} Map     --&gt; (IBM) 
(HAL) 2 Take          --&gt; (HA) 
(HAL) -2 Take         --&gt; (AL) 
(HALLO) [-2] Take     --&gt; 76 
(HALLO) [1 -2] Take   --&gt; (HALL) 
(HALLO) [1 -2 2] Take --&gt; (HL) 
(HALLO) [1 -1 2] Take --&gt; (HLO)


Bugs:

The scheme for a list of sequences is not fully consistent with Mathematica. 
See Drop for a more advanced implementation.


References:

[1] The Mathematica Book V4.0 "Take"


Author:

Diesmann


SeeAlso:

Drop
Part
MathematicaToSliIndex
getinterval
get

Source:

/var/www/debian/nest/nest-simulator-2.20.0/lib/sli/mathematica.sli
