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

[REBOL] Re: Fun with blocks of words (a tad longish)

From: giesse::writeme::com at: 10-Oct-2001 15:40

Joel Neely wrote:
> >> reduce repeat i 5 [use [.i] [.i: i append [] [.i]]] > == [5 5 5 5 5]
Actually, this is a side effect of SMC. USE rebindes its block at each iteration, so it rebinds your growing [] at each iteration.
> Again we get five references to the same word!
Five different words, but bound to the same context and thus referring to the same value. (Well, maybe this makes them "the same" to you... I don't want to start a new thread on mutability and sameness... ;-)
> >> reduce repeat i 5 [use [.i] copy/deep [.i: i append b [.i]]] > == [1 2 3 4 5]
Non need for copy/deep this way.
> >> apparg: func [b x] [append b [x]] > >> c: repeat i 5 [apparg [] i] > == [x x x x x] > >> reduce c > == [5 5 5 5 5] >> apparg: func ['x] [append [] x] >> c: repeat i 5 [use [j] [j: i apparg j]]
== [j j j j j]
>> reduce c
== [1 2 3 4 5]
> I suspect that this might be a performance choice. Create the > context when the function is defined, and keep it around to avoid > repeating that work every time the function is evaluated.
Yup.
> Errrk? What about recursion?
Value stack. ;-)
> Wot??? I got five homographs! Does USE inside a function body > behave differently than USE at the console level?
Nope. See above. :-)
> Thought 7: There's more going on here than meets the eye. > I need another cup of coffee.
It's just that you were using a literal block before!
> As usual, feedback/comments/corrections/coffee are welcome! ;-)
Heh. :) Being brief, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/