REBOL Document

Extract - Function Summary


Summary:

Extracts a value from a series at regular intervals.

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 - Extract from an offset position

pos - The position

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 blank-face IMAGE BACKDROP BACKTILE BOX BAR SENSOR KEY BASE-TE
XT VTEXT TEXT BODY TXT BANNER VH1 VH2 VH3 VH4 LABEL VLAB LBL LAB TITLE H
1 H2 H3 H4 H5 TT CODE BUTTON CHECK CHECK-MARK RADIO CHECK-LINE RADIO-LIN
E LED ARROW TOGGLE ROTARY CHOICE DROP-DOWN ICON FIELD INFO AREA SLIDER S
CROLLER PROGRESS PANEL LIST TEXT-LIST ANIM BTN BTN-ENTER BTN-CANCEL BTN-
HELP LOGO-BAR TOG]


<Back | Index | Next>

Copyright 2004 REBOL Technologies