Rebol Programming/move

From Wikibooks, open books for an open world
Jump to navigation Jump to search

USAGE:[edit | edit source]

MOVE source offset /part length /skip size /to 

DESCRIPTION:[edit | edit source]

Move a value or span of values in a series.

MOVE is a function value.

ARGUMENTS:[edit | edit source]

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

REFINEMENTS:[edit | edit source]

  • /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 | edit source]

  • catch

SOURCE CODE[edit | edit source]

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
]