REBOL - An overview

REBOL. I first heard of this new programming language several years ago. The name sent shudders down my spine - was it the “REturn of coBOL”? Visions of endless pages of data declarations crawled out of a dark place in my memory and I moved on to another web site while I still had the will to live.

What a shame - I should have had a closer look, because I couldn’t have been more wrong. I don’t know if REBOL (the purists insist it’s pronounced “reb-el”, but I just can’t seem to get past “re-bol”) is ever going to set the programming world on fire, but it is easy to learn, surprisingly powerful and a lot of fun to code.

What is it?

The inventor of REBOL (Relative Expression-Based Object Language) refers to it as a messaging language - “created specifically for the exchange and interpretation of information over the Internet”. One of the major implications of this is that REBOL treats local and remote data sources identically - it doesn’t matter to the REBOL programmer whether files are on the local hard drive, on a web site or FTP server. In practice REBOL sits in roughly the same space as the scripting languages like Perl, Python, VB, and Java.

Multi-tier structure

REBOL has a multi-tier structure. At the base is REBOL/Core, the command line kernel that provides the basic functionality of the language (common to all other modules). On top of this sits REBOL/View (providing GUI and multimedia features) and REBOL/Command (adding “enterprise” functionality like access to databases, external libraries and external applications). At the top of the tree is REBOL/IOS, the Internet Operating System - “a platform for collaborative applications”.

Availability

REBOL/Core and REBOL/View are freely available but not open source. Both are a relatively small download at about 250 kb and 360 kb respectively. REBOL/Command and REBOL/IOS are fully commercial products.

Language Features

Here is a brief overview of the features provided to all other packages by the REBOL/Core module.

Platform Independence

REBOL/Core is intended to be platform independent, as is REBOL/View on systems where a GUI environment is available. I have found this to be a reasonable claim after running REBOL/Core and REBOL/View on Windows, Linux and Macintosh OS9 and OSX (except for REBOL/View on OSX - not available at the time of writing). Both versions are available for a wide range of platforms from Amiga to Windows.

There are some limitations imposed by strict platform independence, one of which is the inability for the free versions to execute external applications. The REBOL folks claim this is to preserve cross-platform compatibility but it is a feature that the language really needs in order to replace other scripting languages on the desktop. Conversely, it is possible to access command line arguments but not all operating systems have the concept of a command line - an odd little inconsistency.

Installation

There is practically no installation required - just unpack the zip archive and run REBOL. If you want to use network features there is some configuration required, but a comprehensive setup page on the REBOL web site (http://www.rebol.com/docs/setup.html) should see you right. REBOL/View comes with an installer that steps you through network setup. If you want to call REBOL like any other program, it will need to be in your system path.

Values

In REBOL, raw data are referred to as values, and each value has a data type. Like most other programming languages, REBOL provides the common native data types like numbers, characters, strings, and so on. But it also includes many others such as URLs, email addresses, SGML-style tags, and files all as standard data types in the language.

Words

Words are the labels used by REBOL. Words may be variable names, function names, or just … words!

Variable names:

my-name: "tech.thingoid"
pay-me-now: $1000000.00

Function names:

add-up: func [this that] [this + that]

factorial: func [x] [
    either x > 1 [
        x * factorial (x - 1)
    ] [
       1
    ]
]

Literal words:

'blue
'something

Blocks

Words, making up both program code and data, are collected into blocks. Blocks are delimited by square brackets, and can be assigned to a variable name just like any other value.

For example, the following works just as well as the previous definition of the “add-up” function:

params: [this that]
procedure: [this + that]
add-up: func params procedure

Blocks are the main structural feature of REBOL scripts.

Network Protocols

A useful collection of network protocols are seamlessly integrated into the language, including HTTP, FTP, SMTP, POP and TCP. A good demonstration of the simplicity of REBOL’s networking capability is this one-line email sender:

send someone@email.com "The message."

This prints out the HTML source of the given web page:

print read http://www.melbpc.org.au

Dialects

One of the most exciting features of the language is the ability to virtually rewrite the language using “relative expressions” or “dialects”. This can help simplify otherwise complex tasks. Here is an example using the Visual Interface Dialect (VID) that is resident in REBOL/View:

view layout [image http://www.melbpc.org.au/pict/mpclogox.gif]

It puts the Melb PC logo in a window on the screen:
Image of Melb PC logo

I cover Implementing a GUI with REBOL/View in another article. Third party programmers have also written other dialects including ones for HTML, XML and Flash.

Evaluation of expressions

There are no operator precedence rules in REBOL - all processing proceeds left-to-right. For example:

10 + 20 * 3

gives the result 90 not 70 as primary school mathematics dictates. Use brackets or reorder the operators to make the intention clear. This does not present as much of a problem as you would think at first.

An example script - A batch file renamer

All of the previous code samples in this article can be tried at the REBOL command line. Now I present a short but complete REBOL script.

Firstly every REBOL script has a header that includes some descriptive information, then the code of the script itself. Comments are embedded in the code, preceded by a semi-colon.

rebol rebname.r find-pattern replace-pattern

For example, I may have a set of documents called letter-draft.doc, budget-draft.xls, presentation-draft.ppt, and so on. To change the drafts to final versions, I can enter:

rebol rebname.r draft final

And the job is done.

And for my next trick…

In the next instalment, I outline how to use REBOL/View to make a graphical front end for the renamer.

REBOL resources on the web

First published: PC Update May 2003 (online version updated)