REBOL [
Title: "Lists"
Author: "Aldo Calpini"
Date: 03-Jul-2001
File: %lists.r
]
SIZE: 10000
ITER: to-integer to-string system/script/args
ITER: either ITER < 1 [ 1 ] [ ITER ]
test_lists: func [ /local A Li1 Li2 Li3 ] [
comment [
create a list of integers (Li1) from 1 to SIZE
]
Li1: copy []
for A 1 SIZE 1 [
insert tail Li1 A
]
comment[
copy the list to Li2 (not by individual items)
]
Li2: copy Li1
comment [
remove each individual item from left side of Li2 and
append to right side of Li3 (preserving order)
]
Li3: copy []
Li2: head Li2
while[not tail? Li2] [
insert tail Li3 Li2/1
remove Li2
]
comment [
Li2 must now be empty
remove each individual item from right side of Li3 and
append to right side of Li2 (reversing list)
]
Li3: head Li3
while[not tail? Li3] [
last Li3
insert Li2 Li3/1
remove Li3
]
comment [
Li3 must now be empty
reverse Li1 in place
]
reverse Li1
comment [
check that first item is now SIZE
]
if Li1/1 <> SIZE [
return -1
]
Li1: head Li1
Li2: head Li2
while [not tail? Li1] [
if Li1/1 <> Li2/1 [
return 0
]
Li1: next Li1
Li2: next Li2
]
Li1: head Li1
return length? Li1
]
result: 0
while [ ITER > 0 ] [
result: test_lists
ITER: ITER - 1
]
write %output.rebol rejoin [ result ]