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

[REBOL] Re: link to background on Rebol language design?

From: maximo:meteorstudios at: 20-Aug-2003 13:14

IGNORE MY LAST MAIL, this one is clearer !!! I punched the send button without wanting to...
> -----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... in rebol you can USE in one context data which is BOUND to ANOTHER context! 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 word's value. which is why you can encounter words which actually have 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 a cleaned up 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 "rebel" survive?} printline: does [ print line ] ] print {^/^/WE WILL ACCUMULATE A CODE BLOCK WHICH CONTAINS SOME CODE FROM EACH OBJECT...^/} ; 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" probe code-block print "^/^/>> do code-block^/" ; now run it! do code-block print uppercase {^/NOTICE THAT THE LAST 'print statement ACTUALLY DID A 'probe INSTEAD, SINCE THE OUTPUT 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]}
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 ;-----------------------------------------------------