[REBOL] Re: local vars in functions
From: lmecir:mbox:vol:cz at: 30-Apr-2002 23:03
a little discussion may be useful sometimes:
Ladislav, I disagree.
I don't think this is an adequate proof.
(You didn't observe the scan happening,
so it's a theory, not an observation.)
You are right. It is a theory supported by observation. In
http://www.rebolforces.com/~ladislav/contexts.html (in the MAKE OBJECT!
section) I wrote a Rebol model of the Rebol interpreter behaviour during the
MAKE OBJECT! evaluation. It has proven itself to be accurate, because it not
only described the observed behaviour but it even allowed me to predict
correctly the behaviour of the interpreter in complicated cases I haven't
tried before. The theory is therefore proven as accurately as any theory I
accept to be proven.
In my understanding, context evaluates its blk
argument, and as it moves along from item to item,
finds set-words and their values and adds them
to the new object that it is creating.
I would say the BLK argument is scanned for local
words *as* it is being executed.
Your hypothesis can be easily falsified, if we compare its prediction with
the result of the sample code:
blk: [change at blk 9 first [b:] a: 1 placeholder 2]
c: context blk
I think, that we are in agreement, that after evaluating the first part of
BLK, BLK changes to:
[change at blk 9 first [b:] a: 1 b: 2]
*before* the 7-th element of BLK is evaluated. That means, that when the
9-th element of BLK is evaluated, the interpreter evaluates a set-word b:
instead of the word 'placeholder. At the same time, we can easily find out,
that if we instead do:
blk: [change at blk 9 first [b:] a: 1 b: 2]
c: context blk
we obtain a different result.
Forgive me if I misunderstood. It's not terribly clear.
Regarding your final statement at bottom, would you say
that the following statements are true?
1) "BLK ... scanned for local words" -means-> "BLK is reduced"
2) "... executed" -means-> "made into an object"
It looks, that you understood me well. I would say that neither 1) nor 2) is
true. To be totally accurate, I would have to write the model code mentioned
above that you can find in contexts.html
Feel free to ask if anything remains unanswered.