Download presentation
Presentation is loading. Please wait.
1
REBOL Lists
2
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
3
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
4
Example traversals >> str: "REBOL" == "REBOL"
>> mid: next next str == "BOL" >> head? mid == false >> head mid == "REBOL" >> end: tail str == "" >> back end == "L"
5
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
6
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
7
The End
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.