INDEX?
The 'index? function returns (a natural number that represents) the
current position attribute of the series. In the last example, the
index of a's value and the index of b's value are both 1.
>> a: "1234"
== "1234"
>> index? a
== 1
>> index? "1234"
== 1
The index is a property of the data (value) and NOT of the variable.
LENGTH?
The 'length? function to a series returns a count of the elements
from the index of the series through the end of the referenced
sequence. The length of a's value above is 4, since it refers to a
sequence of 4 elements, and has an index of 1.
>> a: "1234"
== "1234"
>> length? a
== 4
NEXT?
The 'next function produces a series entity referrings to the same
sequence as the argument series, with the index increased by one
(unless the index is already past the end of the sequence, in which
case the result's index is the same as the argument's index.)
Beginning with the last example, evaluating:
b: next a
produces this state of affairs:
a -> {{string! 1 *}}
|
V
<<#"1" #"2" #"3" #"4">>
^
|
b -> {{string! 2 *}}
Evaluating b should produce a result of length 3 that begins
with the character #"2". The value of b is no longer the same as
the value of a since their index attributes are different.
>> a: "1234"
== "1234"
>> b: next a
== "234"
>> length? b
== 3
>> index? b
== 2
>> same? a b
== false
HEAD
The 'head function produces a series that refers to the same
sequence as the argument series, but ALWAYS has an index of 1. The
result of evaluating
head b
is an anonymous series that shares the sequence of the values of a
and b, and has an index of 1. It is indistinguishable from the
value of a. 'head returns a series BASED ON the argument series; it
DOES NOT MODIFY its argument series. This is demonstrated by the
fact that b's value is unchanged after passed it to 'head.
>> a: "1234"
== "1234"
>> b: next a
== "234"
>> head b
== "1234"
>> same? a head b
== true
>> b
== "234"
A similar final state could be achieved as follows:
>> b: next "1234"
== "234"
>> a: head b
== "1234"
The first character remains in the sequence during the time (between
the two input expressions) that no series has an index of 1.
(continued in essay/4)