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

[REBOL] The truth about scope

From: gabriele::colellachiara::com at: 13-Apr-2005 13:01

Hello all, I'll try to say a few words on the topic too. I really hope this helps, and please forgive me if this doesn't make any sense to you. :) REBOL is not the way it is for speed. It's this way because it's simpler, and much more powerful. Yep, simpler. Other languages have scope, REBOL doesn't, so it's actually simpler. And I think this is the source of all your problems: REBOL has no scope . As long as you think in terms of scope, you may get into problems. Now, REBOL gives you the illusion of having something like a scope for "variables". This is just an illusion that is there because it is useful to let new users think that way. You don't have to learn all at once, but can learn one step at a time. Forget about scope and variables. Make your cup of tea empty, so that it can be filled again. :) Everything is data, Gregg says. Let's start from that. So, what is a block? A block is a series of REBOL values. In other words, an ordered sequence of values. More precisely: an ordered sequence of references to values. The "references" thing is an important one. You will have probably noticed the effects of this. The simplest example is:
>> s: "A string."
== "A string."
>> b: reduce [s]
== ["A string."]
>> insert skip s 2 "modified "
== "string."
>> s
== "A modified string."
>> b
== ["A modified string."] The first (and only) element of B is not a copy of the string S, it's a reference to it. S and the first element of B are actually the same value. (Almost, there's a detail I'm not going to reveal here, for the sake of simplicity.) So far, so good. Isn't it? Blocks just contain references to values. They can contain any number of such references. Now comes the scoop: what is a word? A word is a symbol, and a reference to one REBOL value. Is that confusing? Maybe. But that's how things are. A word is like a block with just one value. Don't be fooled by contexts and scope, the value is referenced directly by the word value, just like if it was a block with one value slot. If you think everything it's clear up to here, I'll go on and explain what binding means. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/