Search code examples
rebolrebol3

copy/part with pair in REBOL 3


help copy has the following to say about copy:

USAGE:
   COPY value /part length /deep /types kinds

DESCRIPTION:
   Copies a series, object, or other value.
   COPY is an action value.

ARGUMENTS:
   value -- At position (series! port! map! object! bitset! any-function!)

REFINEMENTS:
   /part -- Limits to a given length or position
       length (number! series! pair!)
   /deep -- Also copies series values within the block
   /types -- What datatypes to copy
       kinds (typeset! datatype!)

The /part refinement can take a number!, series! or pair!. I have not been able to get pair! to work. (I haven't tried series! yet.) Is this not implemented? If it is, how does it work?


Solution

  • The /part pair! refinement works with images. The pair relates to the x/y coordinates as in

    >> img: load %image.png 
    == make image! [519x391 #{
    1D2F9F1D2F9F1C2E9E1C2E9E1B2D9D1B2D9D1B2D9D1B2D9D1D2F9F1C2E9E
    1A2C9C192B9B192B9B1A2C9C1B2D9D1C2E9E1D2EA01...
    >> copy/part img 2x2
    == make image! [2x2 #{
    1D2F9F1D2F9F1D2F9F1D2F9F
    }]
    

    REBOL/View Image Datatype

    And here an example how /part series! is working

    >> s: [a b c d e f g]
    == [a b c d e f g]
    >> ser: skip s 3
    == [d e f g]
    >> copy/part s ser
    == [a b c]