REBOL

REBOL, the Relative Expression Based Object Language (pronounced ['rebl]), is labeled an 'internet messaging language' by its makers. It is an interpreted computer programming language that contains support for many internet services, making it fairly easy to write internet applications such as electronic mail agents or web applications.

REBOL is designed by Carl Sassenrath, former primary developer of AmigaOS.

Contents

Notable features

The REBOL interpreter is available in several editions for more than 40 platforms.

The entire runtime environment is stored in one executable file, which is very compact: 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, enabling one to package and transport the intepreter and scripts on a single floppy disk.

REBOL/View provides platform-independent graphics and sound access, and comes with its own windowing toolkit and widget set. The REBOL community is interlinked 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 a REBOL application.

REBOL is designed to handle a wide range of applications, but specifically aims to make distribution of objects and use of network connections simple. It has many specific data types, including a currency type and a URL type.

REBOL is a context dependent language which provides support for dialecting. A classic example of REBOL's context sensitivity is seen with the word return. Under normal evaluation, return exits a function possibly 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 behave similar to carriage return, moving the "rendering pen" down to the beginning of the next line. REBOL programmers can create their own dialects possibly reusing any existing REBOL word with a different meaning in the context of the dialect.

The source code of the REBOL interpreter is closed. Originally, licensing of the interpreter was required for distribution of commercial applications. Now both REBOL/Core and REBOL/View have been made available for producing distributable commercial applications at no charge. However, extended editions of REBOL/View, which bring capabilities like access to dynamic link libraries or script encapsulation, still require a license.

Examples

Hello World:

REBOL [
   Title: "Hello World Window"
   File: %hello.r
   Date: 12-January-2002
   Purpose: "Display the words in a window"
   Category: [view VID 1]
]

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"
   Category: [web email net 1] 
]

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

(Please note that 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.)

Dialects

REBOL provides a native function called parse which you can use to define domain specific languages, often referred to as 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. Your rules are interpreted by REBOL at runtime; they are not used to generate code. You can include actions to be taken during the parsing process as well.

Using parse against a string allows you 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; the downside is that your data must fit within the standard REBOL lexical form.

Another way to look at this is to say that a dialect is a sub-language of REBOL.

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:

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 ""
]

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.

Here are two sets of commands users might send to the app. Note that 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.

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 regex.
; 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.

External links

fr:Rebol it:REBOL pl:REBOL zh:REBOL

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools