[REBOL] Re: set
From: brett:codeconscious at: 16-Mar-2001 10:27
A few examples, and explanations.
set sets a word to a value
>> set 'myword "test"
>> word-to-set: 'test-word
>> set word-to-set 9
>> set [w1 w2 w3] 4
>> set [w1 w2 w3] [1 2 3]
== [1 2 3]
The piece of code you snipped out was part of a larger context - an object.
>> an-object: make object! [
[ name-of-object: "brett"
[ function1: does [print ["name of object is" name-of-object]]
[ set 'function2 does [ print ["name of the same object"
name of object is brett
name of the same object brett
You can see that function1 and function2 have the same access to the context
of the object but function2 is accessed in the global context instead of the
context of the object.
is a field of the object that is set to a function that was
defined within the context of the object.
is a word that is set in the global context to a function. This
function was defined within the context of the object.
So looking back at Marcus' stringcompose! object. The object keeps all the
parse rules and supporting functions in a nice tidy bundle. Then by using
set Marcus has create a globally available function that uses all the stuff
in the object. You don't even need to refer to the object again - it just
hangs around holding the bits together for the use of the stringcompose
So in this case, it doesn't change the functionality of the program, it
neatens the structure of the progam.