slice - get sequence of values from a variable

SYNOPSIS

<slice $var [$begin [$end [$step]]]>


DESCRIPTION
The slice function returns a "slice" of values from $var, starting at the $begin index (default 0), ending just before the $end index (default number of $var values plus 1), and stepping by $step (default 1). The $var variable is not modified.

The effective index values may be zero through one more than the number of $var values. Explicit negative index values are interpreted as offsets from the end of $var, e.g. -1 is the last value. Out of range index values are silently truncated to the appropriate limit. An empty-string or zero-values index or step is taken as the appropriate default. The step may be negative to iterate backwards. A step of zero is an error.


DIAGNOSTICS
The slice function returns its slice of values in $ret.


EXAMPLE

<a name=main>
  <$var = "a" "b" "c" "d" "e">
  <slice $var 1 4 2>
  Slice: <loop $ret> $ret </loop>

</a>

The output of the above example would be:

Slice: b d


CAVEATS
The slice function is only valid in syntaxversion 8.

Unlike push and pop, out-of-range indexes are not errors. This is because slice returns an array not a single item, so it is acceptable to return zero values.


SEE ALSO
push, pop


Copyright © Thunderstone Software     Last updated: Jul 17 2021
Copyright © 2021 Thunderstone Software LLC. All rights reserved.