Hi, Anton,
I agree with Ladislav (BTW he created, i think, a "perfect" simulation of make
object! in one of his articles).
As you can see here:
>> a: 1
== 1
>> context [
print unset? a ;(1)
a: "b" ;(2)
]
true
the word 'a in the print statement in the block context (1) is unset: it must
be local, because the global 'a is = 1.
Being unset, it is not already initialized with "b", and the expression (2)
has not been executed,
but the interpreter already "knows" that the word 'a is local to the block
context.
Conclusion: before executing the block context, all the set-words are found in
the upper level block, a new context build, all its values set to unset! and
the block bound to the new context.
Only at this time the block is executed. This could be delayed easy, like in a
function, without changing the context work.
Another example will prove that an object can be created without executing all
its block.
Indeed is a "monster" object for a bug in Rebol (someone has reported it to
feedback?):
>> x: does [context [return 1 a: 2 b: 3]]
>> print type? o: x
object
>> print type? o/a
unset
>> print type? o/b
unset
I call It a "monster" because this object fails in many manners:
if this is standard:
>> first o
== [self a b]
this is not standard:
>> probe o
make object! [
a: end ;??????
b: unset
]
neither this:
>> second o
== [
make object! [
a: end
b: unset
]]
and this:
>> third o
== [a:]
---
Ciao
Romano
----- Original Message -----
From: "Anton" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 30, 2002 7:12 PM
Subject: [REBOL] Re: local vars in functions
> 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.)
>
> 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.
>
> 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"
>
> Anton.
>
> > Hi,
> >
> > I don't think, that the difference between CONTEXT and FUNC is as clear as
> > Holger states. First of all, I think, that it is a matter of preferences
> > (which may differ). To demonstrate, that the difference is really small,
> > let's have a look at the following code sample:
> >
> > blk: [change at blk 9 first [b:] a: 1 placeholder 2]
> > c: context blk
> > probe blk
> > probe c
> >
> > Here we see, that the BLK ends up being changed to:
> >
> > == [change at blk 9 first [b:] a: 1 b: 2]
> >
> > Which would yield a different result than
> >
> > make object! [
> > a: 1
> > ]
> >
> > when used as the BLK argument. My observation is, that the BLK argument is
> > scanned for local words *before* it is being executed.
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.