[REBOL] Re: link to background on Rebol language design?
From: maximo:meteorstudios at: 20-Aug-2003 12:54
> -----Original Message-----
> From: Joel Neely [mailto:[joel--neely--fedex--com]]
> Sent: Wednesday, August 20, 2003 8:42 AM
> To: [rebol-list--rebol--com]
> Subject: [REBOL] Re: link to background on Rebol language design?
>
> My (current) mental model for REBOL is:
>
> - a WORD! is just a symbol; nothing more, nothing less;
> - a context is just a dictionary that maps a collection of keys
> (WORD! type) to associated values (any type).
>
[...]
> ... the word YORICK is used in four different contexts. Therefore
> it is (in different "places") associated with different (unrelated)
> values.
but it is used local to those contexts just like any local space in function or within
an object of any other language...
Correct me if I am wrong:
The difference In rebol is that binding seems to be applied individually to each word
instead of being looked up by the current environment.
I said once on this list that one day, your brain "wakes up and smells the bacon" in
rebol. That's just what happens when one liberates himself of the concept of a variable
and undestands what a word really is.
My vision is that your code is the variable and its words are its values. what those
values actually contain or point to is determined precisely when it is encountered, because
it seems that each word stores its binding context by itself... it is not stored in the
current environment or "CONTEXT". The context actually is part of the value. which
is why you can execute which actually has not been set yet, meaning that the word has
not been assigned to a context which has a word with that value!
This is not obvious because most code block oriented functions and methods (commands
like 'func, 'make, etc) will set or fix the binding just before evaluation... which is
why it looks as if its using its current "environment", but actually, its the environement,
which was applied individualy to each word.
to a C programmer, I'd say that each word is like a double referenced variable pointer.
where the first level of reference is the context, and the second one is the actual value
bind. but this is still not completely exact, but is the closest I can map it to.
here is my example of just how powerfull binding is within rebol. This will obviously
confuse any non-rebol programmer and many novice rebolers, but that's what I cooked up
when I brain when click on words and binding. We could make a more simple example, but
I share with you the full version.
to really understand it, actually run the code, it will give comments along with evaluated
code, so its a litle easier to understand "in context ;-)" ...
HTH
-MAx
;--------------------------------------------------------------------
rebol[]
paf: make object! [
line: "The evil joker punches robin"
printline: does [
print line
]
]
kaplow: make object! [
line: "batman hits the mad joker"
printline: does [
print line
]
]
ring: make object! [
line: "the clock rings,"
printline: does [
print line
]
]
kaboom: make object! [
print: :probe
line: {BOOM! will batman survive?}
printline: does [
print line
]
]
; here's the magic!
; extract the printline of each context and add them in one block
code-block: []
append code-block second get in paf 'printline
append code-block second get in kaplow 'printline
append code-block second get in ring 'printline
append code-block second get in kaboom 'printline
line: {Stay tuned for next week's ending of "batman the rebel"}
print ["the word 'line is now set to:" line "^/^/"]
; what is in the block,
print "THIS IS THE CODE WHICH WILL RUN:"
probe code-block
print "^/^/>do code-block^/"
; now run it!
do code-block
print {^/notice that the last print actually did a 'probe instead
it is surrounded by {}. we replaced 'print by 'probe in that context^/^/}
print {if we just prepare a block in the main function,
which contains the same words as the code-block:}
probe [print line]
print{^/it will not print the same thing, because its CONTENT
will be bound globally, see:^/>do [print line]^/}
do [print line]
; and here we reset the binding
print {^/^/In rebol, we can easily change the context of any word
or block, if we bind the code-block we prepared earlier to the
global context, then all the words now point to their equivalents
in the global context: ^/>bind code-block 'system^/>do code-block^/}
bind code-block 'system
do code-block
;-----------------------------------------------------