EXTRACT

REBOL Dictionary 2.0


Summary:

Extracts every n-th value from a series.

Usage:

extract block width

Arguments:

block - The block argument. (must be: block hash)

width - Size of each entry (the skip) (must be: integer)

Refinements:

/index - Position to extract from

n - The n argument. (must be: number logic)

Description:

Returns a new block that contains values that are spaced at regular intervals throughout a specified block. This is useful if you have a block that contains implicit "rows" or "records" of data. The WIDTH is the size of each row.

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]

You can see that by default, EXTRACT works on the first element of each row. To extract a different "column" of the data, use the /INDEX refinement to specify an offset position:


    block: extract/index people 3 2
    probe block
    ["Bob" "Cat" "Ted"]

Of course, extract works on any block 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
    [face IMAGE BACKDROP BACKTILE BOX SENSOR KEY VTEXT TEXT BODY TXT BA
NNER VH1 VH2 VH3 VH4 LABEL LBL TITLE H1 H2 H3 H4 H5 TT CODE BUTTON CHECK
 RADIO LED ARROW TOGGLE ROTARY CHOICE DROP-DOWN ICON FIELD INFO AREA SLI
DER SCROLLER PROGRESS PANEL LIST TEXT-LIST ANIM BTN BTN-ENTER BTN-CANCEL
 BTN-HELP LOGO-BAR TOG]


<Back | Index | Next>

Copyright 2003 REBOL Technologies