Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: set

From: brett:codeconscious at: 16-Mar-2001 10:27

Hi Ryan A few examples, and explanations. set sets a word to a value
>> set 'myword "test"
== "test"
>> myword
== "test"
>> word-to-set: 'test-word
== test-word
>> set word-to-set 9
== 9
>> test-word
== 9
>> set [w1 w2 w3] 4
== 4
>> w1
== 4
>> w2
== 4
>> w3
== 4
>> set [w1 w2 w3] [1 2 3]
== [1 2 3]
>> w1
== 1
>> w2
== 2
>> w3
== 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]] [ ]
>> an-object/name-of-object
== "brett"
>> an-object/function1
name of object is brett
>> function2
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. function1 is a field of the object that is set to a function that was defined within the context of the object. function2 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 function. So in this case, it doesn't change the functionality of the program, it neatens the structure of the progam. HTH Brett