REBOL Lists
REBOL does it differently Other languages: Lists (and similar sequences) are singly-linked head returns the first element of the series tail returns the remainder of the series, minus the head REBOL: Series are doubly-linked, hence traversable in either direction Any reference to a series is a reference to some position in the series head returns the beginning of the series tail returns the end of the series
Traversing a sequence head returns the beginning of the sequence tail returns the end of the sequence next returns the next position in the sequence If already at the tail, returns the tail back returns the previous position in the sequence If already at the head, returns the head head? tests if a position is the beginning of a sequence tail? tests if a position is the end of a sequence
Example traversals >> str: "REBOL" == "REBOL" >> mid: next next str == "BOL" >> head? mid == false >> head mid == "REBOL" >> end: tail str == "" >> back end == "L"
Getting elements from a sequence >> str: "REBOL" == "REBOL" >> first str == #"R" >> second str == #"E" >> last str == #"L" >> pick str 4 == #"O" >> pick str 8 == none
Indexing into a sequence >> str: "REBOL" == "REBOL" >> index? str == 1 >> mid: at str 3 == "BOL" >> at mid 2 == "OL” >> at mid -1 == "EBOL" >> index? at mid -1 == 2
The End