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

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 16, 2001 9:49 AM
Subject: [REBOL] set


> Reading the REBOL/Core manual, I am still uncertain as to what 'set
> accomplishes. I noticed these two functions in a recent post, one using
> 'set and the other not using 'set. What does 'set accomplish?
>
>     exec: func [series [series!]] [
>         if error? try [return do series] [
>             join exec_start [series exec_end]]]
>
>     set 'stringcompose func [
>         {Evaluates a string of expressions, only evaluating
>             executable parens, and returns a block.}
>         Text [String!]] [
>         clear buffer
>         parse/all Text rule
>         buffer]
>
> Ryan C. Christiansen
> Web Developer
>
> Intellisol International
> 4733 Amber Valley Parkway
> Fargo, ND 58104
> 701-235-3390 ext. 6671
> FAX: 701-235-9940
> http://www.intellisol.com
>
> Global Leader in People Performance Software
>
> _____________________________________
>
> Confidentiality Notice
> This message may contain privileged and confidential information. If you
> think, for any reason, that this message may have been addressed to you in
> error, you must not disseminate, copy or take any action in reliance on
it,
> and we would ask you to notify us immediately by return email to
> [EMAIL PROTECTED]
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to