REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 23-Feb-2010 Edit History  

REBOL 3 Datatypes: Block!



Blocks are groups of values and words. Blocks are used everywhere, from a script itself to blocks of data and code provided in a script.

Block values are indicated by opening and closing square brackets ([ ]) with any amount of data contained between them.

[123 data "hi"]  ; block with data
[]               ; empty block

Blocks can hold records of information:

woodsmen: [
    "Paul" "Bunyan" paul@bunyan.dom
    "Grizzly" "Adams" grizzly@adams.dom
    "Davy" "Crocket" davy@crocket.dom

Blocks can contain code:

[print "this is a segment of code"]

Blocks are a type of series and thus anything that can be done with a series can be done with a block value.

Blocks can be searched:

probe copy/part (find woodsmen "Grizzly") 3
    "Grizzly" "Adams" grizzly@adams.dom]

Blocks can be modified:

append woodsmen [
    "John" "Muir" john@muir.dom
probe woodsmen
    "Paul" "Bunyan" paul@bunyan.dom
    "Grizzly" "Adams" grizzly@adams.dom
    "Davy" "Crocket" davy@crocket.dom
    "John" "Muir" john@muir.dom

Blocks can be evaluated:

blk: [print "data in a block"]
do blk
data in a block

Blocks can contain blocks:

blks: [
    [print "block one"]
    [print "block two"]
    [print "block three"]
foreach blk blks [do blk]
block one
block two
block three


Blocks can contain any number of values or no values at all. They can extend over multiple lines and can include any type of value, including other blocks.

An empty block:

[ ]

A block of integers:

[24 37 108]

A REBOL header:

    Title: "Test Script"
    Date: 31-Dec-1998
    Author: "Ima User"

The condition and evaluation block of a function:

while [time < 10:00] [
    print time
    time: time + 0:10

Words in a block need not be defined:

blk: [undefined words in a block]
probe value? pick blk 1

Blocks allow any number of lines, spaces, or tabs. Lines and spaces can be placed anywhere within the block, so long as they do not divide a single value.


The to-block function converts data to the block! datatype:

probe to-block
probe to-block {123 10:30 "string"}
[123 10:30 "string"]


Use block? to determine whether a value is an block! datatype.

probe block? [123 10:30]

As blocks are a subset of the series! typeset, use series? to check this:

probe series? [123 10:30]

Using form on a block value creates a string from the contents contained in the block:

probe form [123 10:30]
123 10:30

Using mold on a block value creates a string from the block value and it's contents, thus allowing it to be reloaded as a REBOL block value:

probe mold [123 10:30]
[123 10:30]

  TOC < Back Next > - WIP Wiki Feedback Admin