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

[REBOL] Re: The truth about scope

From: lmecir:mbox:vol:cz at: 14-Apr-2005 9:36

Hello Michael: ....
>>Carl usually says "indefinite scope" in Rebol. To say itmore explicitly, >>it means, that the binding of words doesn't depend ontheir "positions" >>at all (like in the String example above, Rebol wordsdon't "know" their >>"positions"). >> >> > >That's what I just got in the last days consciously. But this should be >also one of the requirements of a keywordless language. >
Keywordlessness doesn't influence this, as other (less dynamic) languages illustrate, see below.
> For instance (as >far as I understand) in Lisp you can do almost the same powerful things as >in Rebol just by the raw power of lambdas. But one has a fixed binding >model >
The word "almost" is appropriate as well as the "Fixed Binding Model" notion (thank you). That is an exact description of the way the scope rules are supposed to work. There is a fixed set of rules relating positions of variables in the code (scope) and their binding. The problem is, that "Fixed Binding Model" isn't best suited for a dynamic language, because to know the binding one has to know the scope of the variable. (See the need to introduce macros in Lisp, Lispers usually don't understand, that there may be a language not needing macros at all.) As opposed to that Rebol has got "Computed Binding Model", where: 1) every variable "knows" its binding, i.e. the binding is a "data component" of the "variable", which is a "data value" like e.g. integer 2) during execution of "code" the binding of variables is "computed" by functions - the first function starting this is usually the Load function, which "creates" every variable bound to the Global Context (i.e. to the System/words object). This is followed by other functions like Use, Func, Repeat, Foreach, Context or Bind, which continue their common job to "compute" binding. This means, that the binding of a word is a result of several applications of these functions, one after another.
> in the way that one knows what variable is bound to what scope when. >
This holds for *both* the Fixed Binding Model and for the Computed Binding Model. The difference lies in the fact, that to know the binding of a variable in the Fixed Binding Model one has to know the scope of the variable. For the Computed Binding Model holds, that the binding is a "data component" of a word, i.e. you can *inspect* the binding of a variable at any time (e.g. using some of the functions that can be found in ). The main difference lies in the fact, that the binding is "computed" by the functions mentioned above, not fixed as in the Fixed Binding Model. ....
>I guess this is because at least lambda and the few keywords of Lisp have >a defined meaning, which never changes. In Rebol on the other side if we >can redefine everything and we just have data, then we need the evaluation >model (the rules) and if we want to change something to that we have the >bind function which can do whatever is needed. Isn't in this sense bind >also a keyword, as also in Rebol there have to be some words which have to >be "bound" to the core concepts of Rebol in order to make it working at >all ? >
No, you can use any appropriate function to change binding of a variable, not just the Bind function. See e.g. the Context function, which works differently than the Bind function, or the Load function, which works differently than Bind etc. ....
>??? :-) I'm still trying to get what was Carls intention in developing >Rebol, as it sounds nice to be able use every possible word in some >context. On the other side if one uses 'parse this isn't anymore exactly >this, because to me 'parse is more like a traditional mechanism (even >though one can bind a chosen amount of words there also). >
Right again, Parse is "like a traditional mechanism". But I would underline the word *like*. The difference is, that no other language is able to "manipulate itself" in this way. When you use Regular Expressions in some languages, you can manipulate strings. This is exactly the role Parse has when manipulating strings. OTOH, Parse can manipulate blocks, which is the area, where it is unique, no such instrument exists in any other language. This leads to the possibility to write: view layout [button "Hello world"] without a need to change Rebol syntax. This property of Parse isn't actually a property of Parse at all. This is a property of Rebol. Rebol is designed so, that it can "manipulate" itself. You could do it without Parse, you can even define your own version of Parse using other Rebol functions if you wish and the Computed Binding Model is one of the parts of this "puzzle".
> Just binding a >block to a new context and evaluating it is dangerous and thus not really >recommended, so again 'parse should be used. But this could be done in >every traditional language as well (maybe not as comfortable, but still). >
How would you define your own If version in C without breaking the C standards?
>So either I have always a trusted source and can happily evaluate and >bind, it's very valuable to be able to do it, but if not and I have to >start parsing, doesn't Rebol actually looses some if its power ? >
No, this feature is more powerful than the ability to bind, but they are related as I tried to explain above, i.e. the malleability of the language is a result of the way the language was designed including the Computed Binding Model. -Ladislav