REBOL Programming/move

From Wikibooks, open books for an open world
< REBOL Programming
Jump to: navigation, search

USAGE:[edit]

MOVE source offset /part length /skip size /to 

DESCRIPTION:[edit]

Move a value or span of values in a series.

MOVE is a function value.

ARGUMENTS:[edit]

  • source -- Source series (Type: series)
  • offset -- Offset to move by, or index to move to (Type: integer)

REFINEMENTS:[edit]

  • /part -- Move part of a series
    • length -- The length of the part to move (Type: integer)
  • /skip -- Treat the series as records of fixed size
    • size -- Size of each record (Type: integer)
  • /to -- Move to an index relative to the head of the series

(SPECIAL ATTRIBUTES)[edit]

  • catch

SOURCE CODE[edit]

move: func [
    "Move a value or span of values in a series." 
    [catch] 
    source [series!] "Source series" 
    offset [integer!] "Offset to move by, or index to move to" 
    /part "Move part of a series" 
    length [integer!] "The length of the part to move" 
    /skip "Treat the series as records of fixed size" 
    size [integer!] "Size of each record" 
    /to {Move to an index relative to the head of the series}
][
    unless length [length: 1] 
    if skip [
        if 1 > size [throw-error 'script 'out-of-range size] 
        offset: either to [offset - 1 * size + 1] [offset * size] 
        length: length * size
    ] 
    part: copy/part source length 
    remove/part source length 
    insert either to [at head source offset] [
        system/words/skip source offset
    ] part
]