Expand/Shrink

head

Definition: sequence res = head(sequence src, integer size=1)
Description: Return the first size elements of src.

src: the sequence from which elements will be obtained.
size: number of elements required. If omitted, returns src[1..1].

Returns a sequence containing the first size elements of src, unless it is shorter than size, in which case src is returned unaltered.
pwa/p2js: Supported.
Comments: NB when size is omitted this returns src[1..1] rather than src[1].
Example:
s2 = head("John Doe", 4)                -- s2 is John
s2 = head("John Doe", 50)               -- s2 is John Doe
s2 = head({1, 5.4, "John", 30}, 3)      -- s2 is {1, 5.4, "John"}
s2 = head({1, 2, 3, 4})                 -- s2 is {1}
Implementation: See builtins\pseqc.e (an autoinclude) for details of the actual implementation.