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

[REBOL] Re: Please help me out

From: gerardcote::gmail at: 24-Aug-2010 8:50

Hi all, Just in case you missed it in the past, here is some discussion that went between Josh F and Maxim recently and that I found last July 24th. This can be of interest too since it is related - Sorry I couldn't post the link only as I didn't kept the reference, only the contents. ============= = JoshF post : ============= I have a very strange problem with REBOL/View 2.7.6.3.1... If I do this: repeat i 5 [do [print i]] I get five number down the screen as you'd expect. ------------------------------ ----------------- 1 2 3 4 5 However, if I do this: m: [print i] repeat i 5 [do m] Then I get a "** Script Error: i has no value ** Near: print i" error. ----------------------------------------- and Oh, by the way... m: [print i] repeat i 5 m works just fine too. ---------------------------------- As far as I can tell the operations should be identical. Any ideas as to what I'm doing wrong? Thanks! ========================= = Maxim Olivier Adhloch reply : ========================= its a binding issue... you see the i variable is within a block which is evaluated by do, but the binding of the [do m] block is done by repeat. as such, binding does not traverse words. repeat will assign the value of m to your block, but not the values of the words inside of m to i or print. in fact, do is doing this indirectly when its looking at the block. but because i isn't defined outside of repeat... i maps to nothing. now repeat did bind m, but not the values inside of m . this is perhaps the trickiest part of binding. a word and its value are not equal wrt to binding... you will have to reduce the repeat block, so that m is reduced or composed into its value, before repeat can bind 'i . in a very old version of rebol there was "aggressive" binding and it did recurse into words, like you are expecting it, but that caused some impossible to reverse side-effects... so this was removed. in your case, just do: m: [print i] repeat i 5 reduce [ 'do m] ---------------------------------------------------- or m: [print i] repeat i 5 compose/only [ do (m) ] ------------------------------------------------------------------ In fact if I apply the recomendation from Ladislav, using compute instead of eval could have made the real sense easier to grasp from the beginning - at least to me ! Thanks all of you. HTH, Gerard P.S. Now all that is missing for me is some in context use for a real binding study, as could be applied to differents "contexts" - for example when words are not bound to the main R2 dictionary store. This already bogged me down and I have to restart these old projects ... whenI will have more time - just to see if I understand these concepts better now ... after all these long years going up and down myself !