[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(5)
Hi Larry, > one small correction. Yep. Slipped on a banana as I was nearing the finish line. I knew I should have gone to bed - just had to get rid of the "monkey on my back" :) > Of > course, Carl's example was very contrived -- how else could one short script > have 15 uses (one hidden in 'b2) of the word 'b. :-) Indeed. Apart from 'use, hopefully Carl has run out of more uses! Brett.
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(4)
Hi Brett Good job! Your "explanation" agrees well with the one I came up with. Just one small correction. You wrote: > So that "get b" evalutes to b1. "get-it b1" calls the function in the object > and thus returns the value of the word "b" in the object that is associated with "b1". > This value (a string) is then appended to the value (a block) of the global word "var". > 3.3.3) The same goes for the other two iterations, except that for "b3" a > function of the nested object returns the value of "a" in that context. Actually the value of the word 'b in the object referenced by 'b1 is the block [a], which is then appended to the global 'var block. The same for 'b2. For 'b3, get-it returns the function func [][a]. So that >> print mold var [a a func [][a]] The 3 instances of the word 'a are each bound to the separate contexts of 'b1, 'b2, and 'b3 respectively. The evaluation of the a's is done by the print command which reduces the block before forming it, i.e. 'print block prints the string that would be produce by 'reform block. >> reduce var == ["Time" "for you" "to leave!"] >> reform var == "Time for you to leave!" I have included below the script that I used to investigate certain key points in Carl's Conundrum. It also shows how one can access the same data in the anonymous object without using the encapsulated get-it func. Of course, Carl's example was very contrived -- how else could one short script have 15 uses (one hidden in 'b2) of the word 'b. :-) BTW The problem with recycle which I posted can be avoided by naming the anonymous object created by the function 'b. o: make object! [ Fun stuff :-) -Larry - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, July 27, 2000 8:45 AM Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(3) > Well this deserved a response, since it's has consumed so much of my time :) > I do not claim my response to be elegant, but I hope it is practically > accurate. > And I want to know if I'll be eligible for that master's degree! > A description of Carl's Completely Confusing Complex Contexts. > > b: function [] [b] [ > make object! [ > b1: make object! [a: "Time" b: [a]] > b2: make b1 [a: "for you"] > b3: make b2 [a: "to leave!" b: does [a]] > set 'b [b1 b2 b3] > get-it: func [b] [get in b 'b] > ] > b > ] > var: [] > foreach b b: b bind [append var get-it get b] first b ---snip rest--- --code--- REBOL [ Title: "Carl's conundrum" File: %context.r Date: 20-Jul-2000 ] b: function [][b] [ print ["^/function entry: local b type is" type? :b] make object! [ b1: make object! [a: "Time" b: [a]] b2: make b1 [a: "for you"] b3: make b2 [a: "to leave!" b: does [a]] set 'b [b1 b2 b3] get-it: func [b] [get in b 'b] ] print ["^/after object: global b type is" type? get in system/words 'b ] print ["^/after object: local b type is" type? :b] b ] print ["^/after function def: global b type is" type? :b] var: [] foreach b b: b bind [ print ["^/in foreach: local b is" :b "with value" mold get b] append var get-it get b ] first b print ["^/value of global b is" mold :b] print ["^/value of global var is" mold var] print var print "^/Direct access (not using get-it) to data in object^/" var2: copy [] foreach x b [append var2 get in get :x 'b] print mold var2 print var2 ;end of script
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(3)
2.2) bind returns the bound block. 3.3) foreach begins evaluating the body block (bound block) for each element of it's data block - setting the value of it's iterator word as it goes. 3.3.1) On the first iteration the local "b" word is set to the word "b1". 3.3.2) The body block is evaluated. Thus append's parameters are recursively evaluated. So that "get b" evalutes to b1. "get-it b1" calls the function in the object and thus returns the value of the word "b" in the object that is associated with "b1". This value (a string) is then appended to the value (a block) of the global word "var". 3.3.3) The same goes for the other two iterations, except that for "b3" a function of the nested object returns the value of "a" in that context. Fnnnal... print var 4) You can guess. Brett Handley. - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, July 21, 2000 3:10 AM Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(2) > Good explanation. Fun with contexts. I like the "do" not "try" zen yoda thing. Nice touch. Here's the next one to zen. "Fetch these objects from my hand..." > > b: function [][b] [ > make object! [ > b1: make object! [a: "Time" b: [a]] > b2: make b1 [a: "for you"] > b3: make b2 [a: "to leave!" b: does [a]] > set 'b [b1 b2 b3] > get-it: func [b] [get in b 'b] > ] > b > ] > > var: [] > foreach b b: b bind [append var get-it get b] first b > print var > > > Sorry, too little sleep and not enough indefinite extent > makes me write like perl. Nah... > > -Carl > > PS: Actually, explain it, and there's not much left to say. > Really! Plus, MIT will throw in a Master's Degree for you. > > Hint: it's much easier to explain than it looks. But, you've > got to use a dialect to do it. (Now I'll be quiet.) > >
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(6)
send [EMAIL PROTECTED] "subscribe" At 10:09 AM 7/21/00 -0400, you wrote: >Hey, I never got to join the Ally list. How can I sign up? Thanks! > >Keith > >- Original Message - >From: <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Thursday, July 20, 2000 11:55 PM >Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(4) > > >> Thanks. Ok, I see the problem. It's the ol' indefinite extent bug raising >its ugly head again. We'll be fixing it as we proceed next week to add >Modules to REBOL. I'll be starting a discussion about REBOL modules on the >Ally list soon, for anyone who's into that kind of thing. >> >> -Carl >> >> >> At 7/20/00 07:49 PM -0700, you wrote: >> >Hi Carl >> > >> >Just trying to figure out your context test and noticed that recycle >causes >> >an invalid page fault under Win98 Core 2.3 when running this script. >> > >> >REBOL [ >> > Title: "Carl's context test" >> > File: %context.r >> > Date: 20-Jul-2000 >> >] >> > >> >b: function [][b] [ >> > make object! [ >> > b1: make object! [a: "Time" b: [a]] >> > b2: make b1 [a: "for you"] >> > b3: make b2 [a: "to leave!" b: does [a]] >> > set 'b [b1 b2 b3] >> > get-it: func [b] [get in b 'b] >> > ] >> > b >> >] >> > >> >var: [] >> >foreach b b: b bind [append var get-it get b] first b >> >recycle ;recycle here causes crash when doing print >> >print var >> > >> >Wondering if there is a simple explanation for this? Seems like >something >> >about the context referencing is destroyed by recycle. >> > >> >-Larry >> > >> >- Original Message - >> >From: <[EMAIL PROTECTED]> >> >To: <[EMAIL PROTECTED]> >> >Sent: Thursday, July 20, 2000 10:10 AM >> >Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(2) >> > >> > >> >> Good explanation. Fun with contexts. I like the "do" not "try" zen yoda >> >thing. Nice touch. Here's the next one to zen. "Fetch these objects >from >> >my hand..." >> >> >> >> b: function [][b] [ >> >> make object! [ >> >> b1: make object! [a: "Time" b: [a]] >> >> b2: make b1 [a: "for you"] >> >> b3: make b2 [a: "to leave!" b: does [a]] >> >> set 'b [b1 b2 b3] >> >> get-it: func [b] [get in b 'b] >> >> ] >> >> b >> >> ] >> >> >> >> var: [] >> >> foreach b b: b bind [append var get-it get b] first b >> >> print var >> >> >> >> >> >> Sorry, too little sleep and not enough indefinite extent >> >> makes me write like perl. Nah... >> >> >> >> -Carl >> >> >> >> PS: Actually, explain it, and there's not much left to say. >> >> Really! Plus, MIT will throw in a Master's Degree for you. >> >> >> >> Hint: it's much easier to explain than it looks. But, you've >> >> got to use a dialect to do it. (Now I'll be quiet.) >> >> >> >> > >
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(5)
Hey, I never got to join the Ally list. How can I sign up? Thanks! Keith - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, July 20, 2000 11:55 PM Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(4) > Thanks. Ok, I see the problem. It's the ol' indefinite extent bug raising its ugly head again. We'll be fixing it as we proceed next week to add Modules to REBOL. I'll be starting a discussion about REBOL modules on the Ally list soon, for anyone who's into that kind of thing. > > -Carl > > > At 7/20/00 07:49 PM -0700, you wrote: > >Hi Carl > > > >Just trying to figure out your context test and noticed that recycle causes > >an invalid page fault under Win98 Core 2.3 when running this script. > > > >REBOL [ > > Title: "Carl's context test" > > File: %context.r > > Date: 20-Jul-2000 > >] > > > >b: function [][b] [ > > make object! [ > > b1: make object! [a: "Time" b: [a]] > > b2: make b1 [a: "for you"] > > b3: make b2 [a: "to leave!" b: does [a]] > > set 'b [b1 b2 b3] > > get-it: func [b] [get in b 'b] > > ] > > b > >] > > > >var: [] > >foreach b b: b bind [append var get-it get b] first b > >recycle ;recycle here causes crash when doing print > >print var > > > >Wondering if there is a simple explanation for this? Seems like something > >about the context referencing is destroyed by recycle. > > > >-Larry > > > >- Original Message - > >From: <[EMAIL PROTECTED]> > >To: <[EMAIL PROTECTED]> > >Sent: Thursday, July 20, 2000 10:10 AM > >Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(2) > > > > > >> Good explanation. Fun with contexts. I like the "do" not "try" zen yoda > >thing. Nice touch. Here's the next one to zen. "Fetch these objects from > >my hand..." > >> > >> b: function [][b] [ > >> make object! [ > >> b1: make object! [a: "Time" b: [a]] > >> b2: make b1 [a: "for you"] > >> b3: make b2 [a: "to leave!" b: does [a]] > >> set 'b [b1 b2 b3] > >> get-it: func [b] [get in b 'b] > >> ] > >> b > >> ] > >> > >> var: [] > >> foreach b b: b bind [append var get-it get b] first b > >> print var > >> > >> > >> Sorry, too little sleep and not enough indefinite extent > >> makes me write like perl. Nah... > >> > >> -Carl > >> > >> PS: Actually, explain it, and there's not much left to say. > >> Really! Plus, MIT will throw in a Master's Degree for you. > >> > >> Hint: it's much easier to explain than it looks. But, you've > >> got to use a dialect to do it. (Now I'll be quiet.) > >> > >>
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(4)
Thanks. Ok, I see the problem. It's the ol' indefinite extent bug raising its ugly head again. We'll be fixing it as we proceed next week to add Modules to REBOL. I'll be starting a discussion about REBOL modules on the Ally list soon, for anyone who's into that kind of thing. -Carl At 7/20/00 07:49 PM -0700, you wrote: >Hi Carl > >Just trying to figure out your context test and noticed that recycle causes >an invalid page fault under Win98 Core 2.3 when running this script. > >REBOL [ > Title: "Carl's context test" > File: %context.r > Date: 20-Jul-2000 >] > >b: function [][b] [ > make object! [ > b1: make object! [a: "Time" b: [a]] > b2: make b1 [a: "for you"] > b3: make b2 [a: "to leave!" b: does [a]] > set 'b [b1 b2 b3] > get-it: func [b] [get in b 'b] > ] > b >] > >var: [] >foreach b b: b bind [append var get-it get b] first b >recycle ;recycle here causes crash when doing print >print var > >Wondering if there is a simple explanation for this? Seems like something >about the context referencing is destroyed by recycle. > >-Larry > >- Original Message - >From: <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Thursday, July 20, 2000 10:10 AM >Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(2) > > >> Good explanation. Fun with contexts. I like the "do" not "try" zen yoda >thing. Nice touch. Here's the next one to zen. "Fetch these objects from >my hand..." >> >> b: function [][b] [ >> make object! [ >> b1: make object! [a: "Time" b: [a]] >> b2: make b1 [a: "for you"] >> b3: make b2 [a: "to leave!" b: does [a]] >> set 'b [b1 b2 b3] >> get-it: func [b] [get in b 'b] >> ] >> b >> ] >> >> var: [] >> foreach b b: b bind [append var get-it get b] first b >> print var >> >> >> Sorry, too little sleep and not enough indefinite extent >> makes me write like perl. Nah... >> >> -Carl >> >> PS: Actually, explain it, and there's not much left to say. >> Really! Plus, MIT will throw in a Master's Degree for you. >> >> Hint: it's much easier to explain than it looks. But, you've >> got to use a dialect to do it. (Now I'll be quiet.) >> >>
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(3)
Hi Carl Just trying to figure out your context test and noticed that recycle causes an invalid page fault under Win98 Core 2.3 when running this script. REBOL [ Title: "Carl's context test" File: %context.r Date: 20-Jul-2000 ] b: function [][b] [ make object! [ b1: make object! [a: "Time" b: [a]] b2: make b1 [a: "for you"] b3: make b2 [a: "to leave!" b: does [a]] set 'b [b1 b2 b3] get-it: func [b] [get in b 'b] ] b ] var: [] foreach b b: b bind [append var get-it get b] first b recycle ;recycle here causes crash when doing print print var Wondering if there is a simple explanation for this? Seems like something about the context referencing is destroyed by recycle. -Larry - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, July 20, 2000 10:10 AM Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(2) > Good explanation. Fun with contexts. I like the "do" not "try" zen yoda thing. Nice touch. Here's the next one to zen. "Fetch these objects from my hand..." > > b: function [][b] [ > make object! [ > b1: make object! [a: "Time" b: [a]] > b2: make b1 [a: "for you"] > b3: make b2 [a: "to leave!" b: does [a]] > set 'b [b1 b2 b3] > get-it: func [b] [get in b 'b] > ] > b > ] > > var: [] > foreach b b: b bind [append var get-it get b] first b > print var > > > Sorry, too little sleep and not enough indefinite extent > makes me write like perl. Nah... > > -Carl > > PS: Actually, explain it, and there's not much left to say. > Really! Plus, MIT will throw in a Master's Degree for you. > > Hint: it's much easier to explain than it looks. But, you've > got to use a dialect to do it. (Now I'll be quiet.) > >
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(2)
Good explanation. Fun with contexts. I like the "do" not "try" zen yoda thing. Nice touch. Here's the next one to zen. "Fetch these objects from my hand..." b: function [][b] [ make object! [ b1: make object! [a: "Time" b: [a]] b2: make b1 [a: "for you"] b3: make b2 [a: "to leave!" b: does [a]] set 'b [b1 b2 b3] get-it: func [b] [get in b 'b] ] b ] var: [] foreach b b: b bind [append var get-it get b] first b print var Sorry, too little sleep and not enough indefinite extent makes me write like perl. Nah... -Carl PS: Actually, explain it, and there's not much left to say. Really! Plus, MIT will throw in a Master's Degree for you. Hint: it's much easier to explain than it looks. But, you've got to use a dialect to do it. (Now I'll be quiet.)
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(3)
Echos of Yoda. :) - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, July 20, 2000 9:15 PM Subject: [REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(2) > Basically, let go of your normal understanding of programming, and approach > Rebol with no mind. Don't try to analyse it, just 'do it. :-) > > Andrew Martin > Zen Rebol... > ICQ: 26227169 > http://members.xoom.com/AndrewMartin/ > -><- >
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:(2)
Basically, let go of your normal understanding of programming, and approach Rebol with no mind. Don't try to analyse it, just 'do it. :-) Andrew Martin Zen Rebol... ICQ: 26227169 http://members.xoom.com/AndrewMartin/ -><-
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:
Mark wrote: > how about a full explanation in laymens terms > ,ie simple english, just what exactly Rebol > does when the following short script is > loaded / interpreted / executed. I did it from the console. I hope that's not cheating. ;-) >> my-words: [ 'rebol "Blue" ( 7 * 2 ) ] == ['rebol "Blue" (7 * 2)] >> loop 2 [ foreach word my-words [ print word] foreach word my-words probe word ]] rebol Blue 14 rebol "Blue" 14 rebol Blue 14 rebol "Blue" 14 == 14 >> >From the first word: >> my-words: [ 'rebol "Blue" ( 7 * 2 ) ] == ['rebol "Blue" (7 * 2)] 'my-words is assigned the next value, which is a block. Inside the block are three things, a word: 'rebol, a string: "blue" and a parenthesis: (). Inside the parenthesis is an expression, "7 * 2" >> loop 2 [ foreach word my-words [ print word] foreach word my-words probe word ]] 'loop does twice the following block: [ foreach word my-words [ print word] foreach word my-words [ probe word ]] The first 'foreach do-es the block "[print word]" for each word (or item) in 'my-words. Each time "[print word]" is done, 'word is set to each word (or item) in 'my-words. The second 'foreach do-es the block "[probe word]" for each word (or item) in 'my-words. Each time "[probe word]" is done, 'word is set to each word (or item) in 'my-words. When 'word is evaluated, it returns the word or item assigned by the 'foreach after evaluation. To get the typed in value for the parenthesis, don't evaluate it. >> third my-words == (7 * 2) To evaluate it, just 'do it. >> do third my-words == 14 I hope that helps! If not, please ask. Andrew Martin Let go, Luke... ICQ: 26227169 http://members.xoom.com/AndrewMartin/ -><-
[REBOL] REBOL SCOPING / CONTEXT EXPLANATIONS Re:
[EMAIL PROTECTED] wrote: > REBOL [] > > my-words: [ 'rebol "Blue" ( 7 * 2 ) ] > > loop 2 [ foreach word my-words [ print word] foreach word my-words [ probe word ]] When the script is loaded, the ascii text is converted to a block of REBOL values. The first value of the block here is the set-word "my-words:", the second is the block "['rebol ...]" etc. Just after loading, the block (that is, every word in it, recursively) is bound to the global context (system/words). So "my-words:" is bound to system/words, "'rebol" is bound to system/words, and so on with "*", "loop", "foreach" etc. When the block is executed, the block "['rebol ...]" is assigned to "my-words" in the global context, because "my-words:" is bound to the global context. "loop" is bound to the global context, where it means the native function LOOP. So the block "[foreach word ...]" is executed twice. "foreach" is bound to the global context, so the native function FOREACH is evaluated. It gets its arguments, "word", "my-words" (wich is evaluated to the block it means) and "[print word]". It creates a new context, containing only the word "word". The block "[print word]" is then bound to that context: this process leaves "print" untouched (that is, bound to system/words) because it is not present in tha new context; "word", instead, is found in the new context and therefore is bound to that. Then the function FOREACH assigns the first value of the block "['rebol ...]" to the word "word" in the new context and evaluates the block "[print word]". Here "print" means the native function PRINT and "word" means "'rebol", as explained above. Then FOREACH goes ahead to the second value of the block (the string "Blue"), etc. The same thing happens for the second "foreach", and so on. HTH, Gabriele. -- Gabriele Santilli <[EMAIL PROTECTED]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/