REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: reverse

reverse  series  /part  length

Reverses a series and similar types. (Modifies)

Arguments:

series [series! gob! tuple! pair!]

Refinements:

/part - Limits to a given length or position

length [number! series!]

See also:

insert   replace   sort   find  

Description

Reverses the order of elements in a series or tuple.

blk: [1 2 3 4 5 6]
reverse blk
print blk
6 5 4 3 2 1

The /PART refinement reverses the specified number of elements from the current index forward. If the number of elements specified exceeds the number of elements left in the series or tuple, the elements from the current index to the end will be reversed.

text: "It is possible to reverse one word in a sentence."
reverse/part (find text "reverse") (length? "reverse")
print text
It is possible to esrever one word in a sentence.

Note that reverse returns the starting position it was given. (This change was made to newer versions.)

blk: [1 2 3 4 5 6]
print reverse/part blk 4
4 3 2 1 5 6

Reverse also works for pairs and tuples:

print reverse 10x20
print reverse 1.2.3
3.2.1

For tuple values the current index cannot be moved so the current index is always the beginning of the tuple.

print reverse 1.2.3.4
4.3.2.1
print reverse/part 1.2.3.4 2
4.3.2.1


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