REBOL
Docs Blog Get-it

REBOL Overview for Scientists, Engineers, Professors, Programmers

By Carl Sassenrath
Revised: 8-Oct-2011

When I hear about a new computer language and want to learn more, I'm not interested in manuals or tutorials. I want a short explanation of what's different and why. That's the purpose of this page.

REBOL is unique in many ways. Its principles emerged over 30 years of language research and development. REBOL takes a different approach; it has different objectives. Most programmers don't get it right away. Some never get it, but those that do gain a new insight into the power a language can provide. They discover a new elegance of expression and computation.

I should also be clear that nothing in the design of REBOL is arbitrary or "done just to be different". There's a reason for everything. You will get a better understanding below.

If you're a computer scientist or professor, here's a summary of the REBOL Design Objectives for Computer Scientists. If you understand what REBOL is really about, I urge you to consider teaching it to your students or others.

Fundamentals

In the domain of computer languages, REBOL is unique in its expressive flexibility and power. It is built on these fundamental concepts:

CONCEPT

DESCRIPTION

Values, words, blocks

The basic elements of the language source form are:

values:represent numbers, times, strings, filenames, URLs, and much more:
123 45.6 10:20 200.80.80 "hello" http://rebol.com
words:are symbols and can be variables (but not always):
print block? string! map-each ?? + =
blocks:combine multiple values, words, and blocks in any order:
[1 2 3] [123 "abc" print 10:20]

These are the building blocks used to represent data, build expressions, define functions, make objects, and create more complex datatypes.

Loading

The source form is converted to binary blocks within memory.

This source line:

123 45.6 10:20 print "hello"

gets loaded as a block of native binary values in memory. Each value is a cell.

123 45.6 10:20 print "hello"

Some details:

  • Values are stored as binary, not strings.
  • We call this series of values a block.
  • Values can be searched, sorted, modified, reordered, or removed.
  • Storage is sequential in memory. Blocks are a type of vector or array.
  • Alone they have no meaning other than their implicit values and order.

Molding

Binary blocks can be converted back to source form.

That's how code and data are output to consoles, stored in files, sent over networks, etc.

The above block is molded back to text as:

123 45.6 10:20 print "hello"

and, that text can be loaded back into memory, as it was originally above.

Interpretation

Blocks can be interpreted in different ways.

The meaning of a block (what it does, what effect it has, what result it produces) depends on how it is interpreted.

It can be interpreted:

  • In a functional way: arguments evaluated by a function
  • As a special grammar: what we call a dialect in REBOL
  • Via parse statements: matching, backtrack, and production
  • With ad-hoc code: however you want to do it

Code = Data

Code and data are the same; the only difference is in how they are interpreted.

  • Both use the same source format.
  • They are indistinguishable in memory.
  • Code can be interpreted as data.
  • Data can be interpreted as code.
  • Both can be saved and loaded from files.
  • Why? It will become more clear below.

Source Format

Here's a summary of the lexical (source) format of the language:

Many literal datatypes

Many types of values are directly represented:

123         ; 64 bit integers
1.2         ; 64 bit decimal (float)
10.2%       ; 64 bit percent (R3)
$10.55      ; precision decimals (R3)
1.2.3       ; tuples (versions, colors)
10:55       ; time
1-Jan-2010  ; dates
720x488     ; points / sizes
"string"    ; unicode characters
#{012233}   ; binary bytes (octets)
<h2>        ; markup tags
%file.txt   ; files
http://rebol.com  ; URLs

Variation of formats

Some values have alternate or extended representations:

1234      ; integer
1'234     ; with separators 

12.3      ; British decimal
12,3      ; decimal for others
1'234.56
1'234,56

10:20
10:20:30
10:20:30.456
10:20:30,456

21/Jan/2010
21-Jan-2010
21-1-2010
2010-1-21

"a string"
{also a string}

#{012233}
64#{ASIz}
2#{000000010010001000110011}

Word format

Many characters are allowed in words.

We allow not just alpha-numeric with underline, but many other characters can be used:

(pending) + ++ +- = == <> !! ? ....

Word variations

These denote special variations in the meaning of words:

word   ; natural value
word:  ; set word
:word  ; get word
'word  ; literal word
/word  ; refinement word
#word  ; issue word (in R3)

Blocks use [ ] brackets

They are un-shifted on US keyboards, and you type them often.

Also, they look like blocks.

data: [123 3:45 "Example"]
if size [print "ok"]

Blocks hold values, words, and other blocks.

Spaces are needed

Words and values must be separated by spaces.

Take note:

a - b  ; is subtraction
a-b    ; is a single word
this-is-1-word!not=math

Other separators include:

[ ] ( ) / " {

Extra space is ignored

Indent or split lines however you want.

So, code can be flattened, inflated, wrapped, or unwrapped.

if size [print "ok"]

if size [
    print "ok"
]

if
size
[
    print "ok"
]

Case insensitive

This is actually important (but sorry, not too geeky.)

print = Print = PRINT

Human language works this way too.

No sequence separators

Separators interfere with the code-as-data principle (below).

Commas in data and arguments aren't used:

this: [1 2 3]  ; not [1, 2, 3]
max 1 2        ; not max(1, 2)

Expression separators aren't used either.

reduce [1 + 2  3 + 4  5 + 6]
 [3 7 11]

When sub-grouping is needed, use blocks.

Functions don't use ( )

Allows uninterrupted sequences of words and values.

head insert tail block select list name

That's a real sentence. Yes, it takes some getting used to -- like learning a human language. After a while, you'll be fluent.

Two string forms

Easier to embed them in each other.

"short string on one line"
{a "string" in a string}
{
    long "multi-line" string
}

Strings with quotes " cannot span multiple lines.

Embedded docs

Documentation strings are embedded and are accessible within the language.

The docs strings are used for help and for auto-doc generation.

sum: func [
    "This function sums a sequence of numbers."
    block "A block of numbers to be summed"
][...]

Two comment methods

Comments can be lexical or in-line.

Lexical comments use semi-colon. (Picked because it's lowercase home row on US keyboards.)

They are stripped when script is loaded:

; Comment to end of line

In-line comments remain in code:

comment {
    In-line comment remains within code.
}

Convenient for commenting out sections of code:

comment [
    if size [print "this code never runs"]
]

Next...

Coming up next... storage, context, and interpretation.

About | Contact | PrivacyREBOL Technologies 2024