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

[REBOL] Re: R: Re: Variable not avilable out of a foreach

From: henrik::webz::dk at: 11-Dec-2007 17:17

On 11/12/2007, at 17.02, Giuseppe Chillemi wrote:
> >> 3) Modify the function body. >> >> get_data: does [...] >> ... >> foreach line database [ >> bind second :get_data 'line >> get_data >> ] >> >> 4) Make your own variety of foreach which does not create its >> own context but uses words with existing bindings. > > Solution 1 and 2 where already taken into consideration and used. I > was > searching for a reason and you gave it to me. Reallu thank you. > Solution 3 is for PRO-develpers. I'll mark you message for a deeper > study > when I'll fully understand the inner working of rebol. > Solution 4... Ehm.. Have already told you I am not one of the PRO- > Developers > ? :-) > > Giuseppe Chillemi
Learn about REBOL bindings and contexts. That lets you do some neat tricks. The FOREACH line creates its own context inside the loop block and LINE for FOREACH is bound to that context. If you begin using a function that holds its own LINE as well, that LINE is not bound to the same context, but is global: line: none ; global LINE print-line: does [print line] foreach line database [ ; a different LINE in its own context print-line ; will not work, just prints "none" ] Solution 1 and 2 work because you are feeding a value from the FOREACH context into the function directly, instead of using the word. Solution 3 alters the context of the function, which is probably (?) slower than 1. Solution 4 I wouldn't do. :-) -- Regards, Henrik Mikael Kristensen