Getting information from a series
A series can contain values of any type, even a mixture of types. It is often important to know how many items a series contains. This is given by the length?
property:
;-- see Chapter05/getting-info.red:
data: [A B C D]
length? data ;== 4
If a series has no items, it is empty—the empty?
function returns true
:
empty-lst: []
length? empty-lst ;== 0
empty? empty-lst ;== true
Selecting an item – pick and /
We can select an item in two ways, using our data: [A B C D]
series:
- By specifying the item index in a so-called path notation, such as
data/3 ;== C
- By specifying the item index with
pick
, such aspick data 3 ;== C
=> Now answer question 6 from the Questions section.
If the item index is a variable, here represented by i
, you need to use the :i
get word notation:
i: 3 data/:i ;== C data/(i);== C ; this alternative works also
Note
This is important to remember, because data/i
doesn't give any error, but returns none
. When the specified index is out of range...