REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Series: Series Information

Pending Revision

This document was written for R2 and has yet to be revised for R3.

Contents

Length?

The length of a series is the number of items (values for a block or characters for a string) from the current position to the tail. If the current position is the head of the series, then the length is the number of items in the entire series.

The length? function returns the number of items to the tail.

colors: [blue red green]
print length? colors
3

All three values are part of the length:

If the position of the color variable is advanced to the next value:

color: next color
print length? color
2

the length becomes two:

Other examples of length?:

print length? "Ukiah"
5
print length? []
0
print length? ""
0
data: [1 2 3 4 5 6 7 8]
print length? data
8
data: next data
print length? data
7
data: skip data 5
print length? data
2

Head?

The head of a series is the position of its first value. If a series is at its head, the head? function returns true:

data: [1 2 3 4 5]
print head? data
true
data: next data
print head? data
false

Tail?

The tail of a series is the position immediately following the last value. If a series variable is at the tail, the tail? function returns true:

data: [1 2 3 4 5]
print tail? data
false
data: tail data
print tail? data
true

The empty? function is equivalent to the tail? function.

print empty? data
true

If empty? returns true, it means there are no values between the current position and the tail; however, there still may be values in the series. Values can still be present before the current position. If you need to determine if the series is empty from head to tail, use:

print empty? head data
false

Index?

The index is the position in a series relative to the head of the series. To determine the index position for a series variable, use the index? function:

data: [1 2 3 4 5]
print index? data
1
data: next data
print index? data
2
data: tail data
print index? data
6

Offset?

The distance between two positions in a series can be determined with the offset? function.

data: [1 2 3 4]
data1: next data
data2: back tail data
print offset? data1 data2
4

In this example, the offset is the difference between position 2 and position 4:


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin