[REBOL] REBOL's scoping rules Re:(2)

2000-07-19 Thread lmecir

Hi,

  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.
(...)
  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

In Rebol you need the core words to start writing the code (no
"reserved words" as in other languages). The core words are all
global and it would have been impossible to declare them as global
in every block. Other languages use a "trick" - the counterparts
of some Rebol global words are not globals, but "reserved words",
that are globally available without any declaration...

Ladislav




[REBOL] REBOL's scoping rules Re:(2)

2000-07-19 Thread giesse

[EMAIL PROTECTED] wrote:

 In REBOL you don't only have two scopes (contexts) - you have a tree of contexts, 
each one with a parent context, the top level context being what you could call 
global variables.

This is probably not true; each context is independent from the
others.

 As you can see, contexts are traversed bottom-up to find the value of a word.

They aren't. BIND simply binds only words that are found in the
context --- the others are left untouched. The binding is static
and no lookup is needed at evaluation time.

 I hope that future REBOL releases will loosen up on this in some way or another.

There are some problems in allowing a word to be removed from a
context. Adding should be feasible, I think.

Regards,
   Gabriele.
-- 
Gabriele Santilli [EMAIL PROTECTED] - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/




[REBOL] REBOL's scoping rules Re:(2)

2000-07-19 Thread mjmalpha

Brett,

Thanks for the insight; I think it is especially helpful
to note:

 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".

With respect to

 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!

can you perhaps construct the simplest example that illustrates
your point ?

Thanks -

Mike Mastroianni

- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, July 18, 2000 10:58 PM
Subject: [REBOL] REBOL's scoping rules Re:


 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.

SNIP