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

[REBOL] Re: Accessing nested Blocks + search in blocks

From: joel:neely:fedex at: 4-Nov-2000 20:36

Hello, Joachim, [rebol-bounce--rebol--com] wrote:
> On 03-Nov-00, Andrew Martin wrote: > >AM Joachim Thomas wrote: > >AM> having this > >AM> > >AM> myblock: [[one [1 2 3]][two [4 5 6]][three [7 8 9]]] > >AM> > >AM> I can extract a value and put it in > >AM> > >AM> myvalue: myblock/1/2/3 > >AM > >AM> but if I change myvalue: the result is only local, not > >AM> global to myblock, so is there a way to assign the > >AM> content of myblock, like a pointer, to the variable...
I'll be delighted to have someone prove me wrong, but AFAIK there is no way to create "shortcuts" to arbitrary "places" in a REBOL data structure. You *can* do this for reference types (e.g., blocks) so that a lame answer to your original question would be shortcut: myblock/1/2 print shortcut/3 shortcut/3: 33 I don't know what your perceived need to do this is, but if you're trying to tweak for speed, the use of a reference to the lowest-level block in the data structure will eliminate some of the traversal.
> By the way, is there a method to search (deep/recursively) > into block, not only at the first level?
One way to write such a thing... deepfind: func [b [block!] v [any-type!] /local c d] [ either found? d: find b v [ d ][ c: b forall c [ if all [block? d: first c d: deepfind d v] [ return d ] ] none ] ] which, given your myblock: [[one [1 2 3]][two [4 5 6]][three [7 8 9]]] does the following deepfind myblock 5 == [5 6] deepfind myblock 'three == [three [7 8 9]] deepfind myblock 1 == [1 2 3]
> And accessing into blocks, like myblock/1/2/3 using > indexes/variables and not direct references? >> i: 1 == 1 >> j: 2 == 2 >> k: 3 == 3 >> myblock/:i/:j/:k == 3
Hope this helps! -jn-