REBOL Technologies

Context-dependent vs. Context-independent Computer Languages

Carl Sassenrath, CTO
REBOL Technologies
17-Jan-2005 21:25 GMT

Article #0104
Main page || Index || Prior Article [0103] || Next Article [0105] || 0 Comments || Send feedback

You will often hear it said that REBOL is a context-dependent computer language. What do we really mean by that?

A lot has been written on this topic, but the notion of context-dependence boils down to this basic concept: To understand what an expression means (ie. to interpret its meaning) do you need to know the context where it is used?

Most computing languages are context-independent, but our natural human languages, as well as REBOL, are context-dependent.

An Example to Help Clarify the Idea

Let's look at a few examples to better understand this concept. If in C or Java you write:

while (number < 100) {
    if (number == 10) result = true;
}

the words WHILE and IF and the order of the expressions that follow are permanently defined by the language itself. They always mean the same thing regardless of where they are found. They are context-independent.

But, you may ask, what about the words number and result? What are they? It is true that as variables they are defined within the scope of a function or object; however, they are simply variables. They do not modify the grammar of the C (or Java) language itself.

In REBOL, if you write the same example:

while [number < 100] [
    if number = 10 [result: true]
]

isn't that also context-independent?

The answer is no. The REBOL language commonly makes such expressions look context-independent for programming convenience. But, in REBOL, all of the words in this example, as well the sequence and structure itself are defined by the context.

REBOL is context-dependent. The meaning of variables as well as the actual grammar of the expression depends on the context of evaluation.

The Default Functional Environment and Code as Data

Normally, for our programming sanity, we allow REBOL code to be evaluated within the context of REBOL's default functional environment. Within that environment, REBOL becomes a context-independent functional language. Words like DO can be used to evaluate a block of values within that environment -- where words like WHILE and IF are defined as functions that each accept a set of arguments in a defined order.

However, in REBOL you can write the above lines as non-code. In fact, when REBOL translates your script file to its internal form (what's actually in memory), it is not code at all. It is data.

To better understand this, you can write:

example:  [
    while [number < 100] [
        if number = 10 [result: true]
    ]
]

Here I've defined the word EXAMPLE to be a block. The items within the block are simply values. Although they look like code to you, they actually have no absolute meaning without knowing their context. They may or may not be evaluated within the functional environment of REBOL. Perhaps they will be evaluated within a specially defined environment -- as what we call a dialect of REBOL.

As a further example, you might rewrite the above expression as:

[set [result: true] if number < 10] while [number < 100]

This is a perfectly valid REBOL expression. However, to properly interpret it, you must know the context in which it is to be evaluated. Perhaps it is being evaluated by a dialected environment, not by REBOL's default functional environment.

To Conclude

Hopefully the above explanation helps you understand a bit more about what we mean when we say REBOL is context-dependent. It is this property that gives REBOL its true power. It makes REBOL more than just a language of execution, it allows REBOL to be a language of communication and a language of persistent representation (storage).

In summary, we can say that most computer languages are context-independent. However, REBOL is not like most computer languages. Similar in some ways to the natural languages we speak as humans, REBOL is context-dependent.

0 Comments

Updated 24-Nov-2017   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code