Judging by previous message on the list, this question will bring a variety
of responses!
Re "global variables".
Coming from a compiled-language background, it was hard for me to learn
about the immediate nature of the message I send to Rebol. More important, I
had to get out of my old ideas of thinking of variables and instead treat
words as symbolising something else. A subtle but profound difference. One
has you thinking like "I have this little box with a value in it. Now I must
remember the various allowable ways to get my value in and out of the box".
The other way leads to thinking like "I will refer to this thing here using
the name x. So now, let's intrepret x as a email".
This relates directly to context-sensitivity. The words-as-symbols idea
means that you can have a description of something that will take on
different values in different contexts. For example, applying a function to
different rebol objects. If you are from an OOP school you may be of the
opinion that this should be done through an object interface - but I believe
that this an actually an paradigm that Rebol allows for, without mandating.
It comes down to how you want to describe it.
A benefit of this approach is that it is providing a lower barrier of entry
for non-programmers. That is, when starting out with Rebol a person may not
even think of such things as scope and contexts (way too abstract) - they
are perhaps, in their mind, using one context, perhaps like in a simple
conversation with someone else.
So now, I don't tend to think of global variables as just that. Instead I
know I can create symbols in a global context, and I can also set symbols in
a specific context. And I can write Rebol descriptions that will work on
both depending on context!
Brett.
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 19, 2000 11:49 AM
Subject: [REBOL] REBOL's scoping rules
> I've been wondering what the reasoning behind REBOL's scoping rules was
for
> awhile. In C, for instance, any variable that you declare in a function is
> "automatic" (that's what C calls them anyway :). They're automatically
local
> to the function they're defined in, etc.
>
> Why does REBOL have variables be globally scoped by default? I ran into
this
> a few days ago when I asked the list for assistance, and people helpfully
> replied (thank you). One of the things people pointed out was that I
wasn't
> being careful with my recursion and kept using the same global variable
over
> and over again.
>
> Perl takes a similar approach, where everything is global unless you
declare
> the variable 'local' or 'my', but I always assumed that this was just
> because of Perl's heritage as a "throw away" script language, in which
cases
> you really don't have to worry about scoping so much.
>
> PHP takes a completely opposite approach. Any variable you declare is
local
> to a function, and you can't even get at global variables unless you
> explicitly get the variable through the $GLOBALS associative array, or
> declare a variable 'global' in your function.
>
> Anyway, I'd really like to understand why REBOL works the way it does in
> this respect, so if anyone has any insight to give I'd love to receive it.
> Thanks so much.
>
> Keith
>