REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 3-Aug-2010 Edit History |
Extracts a value from a series at regular intervals.
Arguments:
series [series!]
width [integer!] - Size of each entry (the skip)
Refinements:
/index - Extract from an offset position
pos - The position(s) [number! logic! block!]
/default - Use a default value instead of none
value - The value to use (will be called each time if a function)
/into - Insert into a buffer instead (returns position after insert)
output [series!] - The buffer series (modified)
Returns a series of values from regularly spaced positions within a specified series. For example:
data: ["Dog" 10 "Cat" 15 "Fish" 20]
probe extract data 2
["Dog" "Cat" "Fish"]
Essentially, extract lets you access a series as a record or "row" of a given length (specified by the width argument). The default, as shown above, extracts the first value. If you wanted to extract the second value (the second "column" of data):
data: ["Dog" 10 "Cat" 15 "Fish" 20]
probe extract/index data 2 2
[10 15 20]
In the example below, the width of each row is three:
people: [ 1 "Bob" "Smith" 2 "Cat" "Walker" 3 "Ted" "Jones" ] block: extract people 3 probe block [ 1 2 3 ]
block: extract/index people 3 2
probe block
["Bob" "Cat" "Ted"]
Of course, extract works on any series, not just those that appear in a row format (such as that above). The example below creates a block containing every other word from a string:
str: "This is a given block here"
blk: parse str none
probe blk
["This" "is" "a" "given" "block" "here"]
probe extract blk 2
["This" "a" "block"]
probe extract/index blk 2 2
["is" "given" "here"]
Here is an example that uses extract to obtain the names of all the predefined REBOL/View VID styles:
probe extract system/view/vid/vid-styles 2
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |