[REBOL] Re: Confused about "word" forms
From: henrikmk:gmai:l at: 2-Dec-2010 9:35
On Sun, Nov 28, 2010 at 5:52 AM, Duke Normandin <dukeofperl-ml1.net> wrote:
> Hello List....
> First of all, the term "form" is confusing to me. Would someone give
> me an appropriate synonym.
I think of how REBOL separates words and strings. FORM is simply a way
to convert a word, a value to a string, so it can be printed or
transported in a non-REBOL environment.
If you want to go the other way, go from string to code, there are
several ways: DO, LOAD, TO-BLOCK, depending on your needs.
If you want to serialize values properly for storage or transport in a
non-REBOL environment, use MOLD/ALL instead of FORM.
> I understand that a Rebol "word" is not a variable bound to a datatype
> as in other programming languages. It is merely the "name" of a
> container which can hold any Rebol =A0datatype; which itself has the
> "word!" datatype.
Yes, that's almost it. Words are symbols, a single identifier that can
be used for anything. Furthermore, words can be bound to contexts, so
they can hold different values, depending on which context they are
But very importantly, words may not have any values at all, as the
words themselves are data:
words: [luke skywalker]
The words 'luke and 'skywalker don't necessarily refer to anything. It
is the block that makes meaning of the words, and they can be parsed
by parsers. This is what is going on when you create a GUI with the
Visual Interface Dialect, if you are using REBOL2.
> Assuming the Rebol word "age", if I want to have the name of the
> container returned to me, I would use the syntax (form) 'age. Correct?
Somewhat correct. REBOL does not backtrack values to words, so you
can't deduce that a block a value of a specific word.
> Where does the "lit-word" datatype come in? I don't get the
lit-word!s are ways of expressing words that are not to be reduced to
values, but to words.
If you type:
** Script Error: a has no value
** Near: a
But if you type:
You get the word back.
If you set:
>> a: 5
>> reduce [a 'a]
== [5 a]
>> reduce reduce [a 'a]
== [5 5]
This is useful when building content for dialects.
If you try to access the lit-word!, it becomes a word!, as you will
notice in the code example to your next question.
> If I want to have assign something to the "age" container, I would
> age: 35
> is the ":" the "set-word!" datatype.
> If I want the "contents" of age, I would use:
> :age and have 35 returned to me. is the prefixed ":" the "get-word!"
No, the whole word becomes the set-word! and get-word! type.
If you build a block and study it:
foreach val [a 1 :a b: c 'd "boo" %test  #stuff 2.4] [probe type? val]
You will see the types for each element in the block and types are
largely identifiable by REBOL by what characters are appended or
prepended to the word or value. A %-sign indicates a file!, a # is an
issue!, square brackets become blocks, etc.
> I'm getting all balled up with the terminology - how is an "action" -
> like "get the contents of the word called "age", a datatype?
I'm not sure I understand the question.
> Also, what's the difference between using:
> age: 45
> SET age 45
When using a set-word!, it's the simplest way to set a value.
SET is useful in ways where the 'age word is not directly available,
but is accessible from another word, i.e. at times where a set-word!
would be cumbersome to use.
But there is more to both get-word! and set-word!:
get-word! is useful, if you want to obtain a value and you want to be
certain that no evaluation takes place, in case the word contains a
set-word! is useful, if you want to determine the binding of a word to
>> a: make object! [set 'b 1 c: 2]
** Script Error: Invalid path value: b
** Near: a/b
== 2 ; meaning that 'c is bound to the 'a context
== 1 ; meaning that 'b is not bound to the 'a context.
That's it for me. There are other people who can lead you much deeper
into the rabbit hole. :-)
Henrik Mikael Kristensen