REBOL

From Wikipedia, the free encyclopedia

REBOL
Image:REBOL-logo.png
Paradigm: multi-paradigm
Appeared in: 1997
Designed by: Carl Sassenrath
Developer: REBOL Technologies
Latest release: Core 2.6.2, View 1.3.2 / 2006
Typing discipline: dynamic, strong
Influenced by: Self, Lisp, Forth, Logo
OS: Cross-platform
License: freeware, commercial, open mezzanine, closed source
Website: www.rebol.com

REBOL, the Relative Expression Based Object Language (pronounced ['rebl]), is a data exchange and programming language designed specifically for network communications and distributed computing. Its designer, Carl Sassenrath, calls it a 'messaging' language, and says this about it: "The main idea of REBOL is that it gets used for: server, client, communications between them, and storage on them. The power of REBOL comes from its unique integration of programming language concepts and meta-data language concepts. The ultimate goal of REBOL is to provide a new architecture for how information is stored, exchanged, and processed between all devices connected over the Internet. It [REBOL] is meant to be used for the semantic exchange of information between people and machines."

Contents

[edit] History

First released in 1997, REBOL was designed over a 20 year period by Carl Sassenrath, the architect and primary developer of AmigaOS, based on his study of denotational semantics and utilizing concepts from the Lisp, Forth, Logo, and Self programming languages.

REBOL/Command, which added strong encryption and ODBC access, was released in September 2000.

REBOL/View was released in April 2001, adding graphical capabilities on top of the core language.

REBOL/IOS, an extensible collaboration environment built with REBOL was released in August 2001.

The REBOL SDK, providing a choice of kernels to bind against, as well as a preprocessor, was released in December 2002.

[edit] The Language

[edit] Programming

REBOL is a high-level, interpreted, multi-platform, multi-paradigm, dynamically reflective, symbolic programming language. It is also strongly homoiconic—meaning that code and data have the same representation—making it very suitable for metaprogramming.

It supports structured, functional, and prototype-based programming. REBOL is not a pure functional language; imperative programming is supported by using functions with side-effects; nor is it a pure object-oriented language, having non-object datatypes and support for other programming paradigms. REBOL is particularly well suited for Language Oriented Programming; more specifically Dialecting.

REBOL is dynamic, and dynamically typed (values are strongly typed, variables are not). It uses garbage collection for memory management, and supports exception handling and dynamic name resolution (through computed binding).

[edit] Data Definition and Exchange

To support its use as a data exchange language, REBOL has minimal syntax with the following properties:

  • There are no statements; expressions are the primary semantic unit.
  • There are no keywords
  • It is punctuated using only whitespace and [ ] ( ) " { } as delimiters
  • There is a wide range of native datatypes, many of which are defined by their lexical form. (see below)

As a data language, REBOL data is comprised of strongly typed values; it supports more than 30 native data types. As in many programming languages, there are basic values like integers, decimal numbers, and strings. REBOL extends the range of datatypes identified by their lexical form to include values such as email addresses (name@host.dom), URLs (http://www.rebol.com), markup tags (<b>, <font size="2" color="blue">), money values ($100.00, USD$25.25), dates (30-Nov-2005, 1-Dec-2005/10:30-7:00), times (12:00:00), coordinate pairs (5x5), tuples (255.255.255, 192.168.100.1), and words (how are you?). These datatypes use lexical forms familiar to many non-programmers to facilitate its use as a data exchange language. REBOL's main data structure, used for grouping values, is a block!, which is somewhat comparable to a list in Lisp.

[edit] Implementation

The REBOL interpreter is available in several editions (/Core, /View, /Command, /Base, /Face and /Pro). At the time of this writing the /Core version, which is a subset of all other versions except /Base, was available for 43 platforms.

The source code of the REBOL interpreter is proprietary. Both REBOL/Core and REBOL/View have been made available for producing distributable commercial applications at no charge. Extended editions, such as REBOL/Pro, still require a paid license; they add features like ODBC data access, the ability to use dynamic link libraries, and the option to create standalone EXE files.

The runtime environment is currently stored in a single executable file. REBOL/Core, the console edition, is about 300kB and REBOL/View, the graphical user interface edition, is about 650kB in size. Application scripts are rarely more than a few kilobytes, so you can fit the interpreter and scripts on a single floppy disk, send application scripts in email messages, or run them over the Internet.

It contains support for many Internet protocols, making it easy to write internet applications such as electronic mail agents or web applications.

REBOL/View provides platform-independent graphics and sound access, and comes with its own windowing toolkit and extensible set of styles (UI widgets). With it, you can build distributed GUI applications. Due to REBOL's dialecting model, it is a lightweight solution for developing x-internet applications.

The REBOL community is linked through a "REBOL desktop", a graphical representation of REBOL-related files stored on the Internet that is installed together with the REBOL interpreter. The REBOL desktop itself is an open source REBOL application.

[edit] Examples

Hello World:

In the console, you can just type:

 print "Hello World!"

A cross-platform GUI version could be done like this:

REBOL [
   Title: "Hello World in a Window"
   File: %hello-view.r
   Date: 12-January-2002
]

view layout [
    text "Hello world!" 
    button "Quit" [quit]
]

And here is a simple internet application that uses two internet services, HTTP and SMTP:

REBOL [
   Title: "Web Page Emailer"
   File:  %sendwebpage.r
   Date:  12-January-2002
   Purpose: "Get an HTML document from the web and send it through e-mail"
]

send branko@collin.example read http://www.rebol.com

The Header section, beginning with the word Rebol, is required in scripts so the interpreter knows where the script begins. The header need comprise only REBOL []; however, good practice encourages a verbose, descriptive header such as shown in the examples.

[edit] Dialects

REBOL is a context dependent language that provides support for domain-specific sublanguages called dialects. An example of REBOL's context sensitivity can be seen with the word return. Under 'normal' evaluation, return exits a function passing back a result value. In the context of the Visual Interface Dialect (VID), an occurrence of the word return causes the layout engine to simulate a carriage return, moving the "rendering pen" down to the beginning of the next line. REBOL programmers can create their own dialects, reusing any existing REBOL word and giving it a different meaning in the context of that dialect.

Dialects are usually implemented by functions processing REBOL blocks in a specific way (string processing can be used too, see examples below). Similarly, as with other functions, we can discern native dialects (implemented by native functions) and dialects written in REBOL.

Dialect examples:

  • do dialect - this is the 'normal' REBOL as the do function 'understands' and interprets it (native)
  • reduce dialect - a modification of the do dialect collecting the results (native)
  • compose dialect - a modification of the reduce dialect evaluating parens only (native)
  • function spec dialect - a dialect used for function header specification (native)
  • parse dialect - a tool to specify BNF-like grammar parsing rules (native)
  • VID - a dialect specifying Graphical User Interface, implemented as a layout function (mezzanine)

A user can create dialects using any REBOL functions, but reduce and compose functions are better suited than other functions and the parse function is specifically optimized for that purpose.

The parse function's purpose is to analyse and interpret dialects by specifying parsing expression grammar rules in a BNF-like format, much as you would for a parser building tool like yacc or GNU bison. The rules are interpreted by REBOL at runtime. Actions can be included to be taken during the parsing process as well.

The parse function can be used to process REBOL blocks or REBOL strings.

Using parse against a string allows for near-complete flexibility, but requires more effort, as it is a lower level approach. Block parsing makes it easier to create dialects, but there is a tradeoff. In block parsing mode, REBOL handles the lexical scanning for you and your rules are written at the level of REBOL values, not characters and delimiters. The up-side to this is that you can write your rules at a much higher level of abstraction, but your data must fit within the standard REBOL lexical form.

[edit] Grammar Rules

The rules you feed to the parse function are, themselves, written in a dialect of REBOL. When parsing strings, a subset of REBOL datatypes can be used in rules; in block parsing mode, all REBOL datatypes can be used along with some other features that make building sophisticated dialects easier.

Rather than try to cover all the details of writing dialects, I'll just provide a couple small examples:

[edit] String Parsing Example

This first example will parse a string, looking for some specific words, and copying parts of the data out which are variable, and that may be used elsewhere. In this example, all the parts copied from the string are, themselves, strings.

strings: [
    "write Graham a thank-you note"
    "send Allen the new source code"
]

foreach string strings [
    print string
    ; Our rules go in a block, enclosed by square brackets
    parse string [
        ; Each string should start with one of these words. COPY will 
        ; copy the text of interest so we can use it later.
        copy how ["write" | "send"] (print ["How:" how])
        ; Now, copy everything up to the next space, which should 
        ; then be followed by either "a" or "the". We use parenthesis
        ; to define actions to take when a rule succeeds.
        copy who to " " ["a" | "the"] (print ["Who:" who])
        ; Finally, copy everything to the end of the string.
        copy what to end (print ["What:" what])
    ]
    print ""
]

[edit] Block Parsing Example

Let's say you have a file analysis utility, and you want to provide an easy way for users to specify which files to operate on, what times to run it, where to post the results, and who to notify. A dialect could be used to provide a flexible text-based interface for this kind of task.

The dialect allows for multiple items, alternate word orders, and optional words that a person might include for readability, but which shouldn't affect the program's operation.

Here are two sets of commands users might send to the app:

command-blocks: [
    [
        analyze %test-1.txt %test-2.txt 
        post results to http://www.wikipedia.org/results.dat
        notify rebol-xyz@wikipedia.org at 10:00 and again at 10:00pm
    ]
    [
        at 10:00 and at 10:00pm analyze %test-1.txt notify 
        rebol-xyz@wikipedia.org and reb-guy@wikipedia.org 
        post to ftp://wikipedia.org/results.dat
    ]
]

; Words that have an apostrophe before them are literal words we want to match.
; Words that end with an exclamation are datatypes we want to match.
; SOME means "one or more". Like "+" in a regexp.
; OPT means optionally, i.e. "zero or one".
; SET causes a word to refer to the value matched for later use; like setting
;   a variable.

foreach block command-blocks [
    print mold block
    parse block [
        some [
            ['analyze some [set file file! (print file)]]
            | ['notify some [set who email! opt 'and (print who)]]
            | ['at set when time! (print when)] 
            | ['post opt 'results 'to set target url! (print target)]
            | 'again
            | 'and 
        ] to end
    ]
    print ""
]

In the example above, the file, email, time, and url values are all native datatypes in REBOL, so the values extracted during the parse operation could be directly applied in REBOL expressions. For example, the who value could be used with the send function to send email notifications, and the url value with the write function to post the data.

[edit] External links

Wikibooks
Wikibooks has a book on the topic of