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

Reply via email to