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

[REBOL] Re: Block Creation Re:

From: joel:neely:fedex at: 19-Oct-2000 10:21

Hi, Carl, Carl Read wrote:
> Thanks for all the replies on this everyone - I'm a little the wiser > now. >
I'm glad to see from the replies that other folks can do a better job of reading the entire question than I did... ;-) Sorry if my first answer was a bit too hasty!
> It was in a function I noticed the difference and I can see how it'd > be useful to be able to create a new block with the first call of a > function while having the subsequent calls not clear the block's > contents. >
At the risk of sounding picky, I think the wording of this sentence may allow a misunderstanding of what's happening. The "first call of a function" does *NOT* "create a new block". To make a simple example. After evaluating... phlarp: func [a [string!] /local b] [ b: [] append b a ] ...the literal block that is the second element of the body of PHLARP is not a request for REBOL to create another empty block, it is *the* empty block to which B is set. Subsequent modifications to B are, via that reference, modifying the literal block (second element of the body of PHLARP) to which B refers.
>> phlarp "hi"
== ["hi"]
>> source phlarp
phlarp: func [a [string!] /local b][ b: ["hi"] append b a ]
> This is what I was actually trying to do... > > block: [[[]]] > > (for inserting stuff into later), and while the following works as I > wanted... > > block: to-block "[[]]" > > I notice that this doesn't... > > block: to-block [[[]]] > > Because, I assume, the inner blocks are not created anew? >
Almost. In the case of block: [[[]]] we are asking REBOL to set BLOCK to a particular block value that already exists, where in block: to-block "[[]]" or block: to-block [[[]]] we are asking REBOL first to create a new block and then set BLOCK to refer to it. Therefore, in block: [[[]]] it is actually the case that *none* of the blocks at *any* level of nesting are being created anew. Having said all of that, please critique my next post for another way to approach this point. As it is the most F of FAQ for REBOL (as far as I have observed on this list), I've been wrestling with the issue for how to describe what's happening for quite some time. -jn- -- ; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677 REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] { | e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]