[REBOL] Re: Accessing nested Blocks + search in blocks
From: joel:neely:fedex at: 4-Nov-2000 20:36
> On 03-Nov-00, Andrew Martin wrote:
> >AM Joachim Thomas wrote:
> >AM> having this
> >AM> myblock: [[one [1 2 3]][two [4 5 6]][three [7 8 9]]]
> >AM> I can extract a value and put it in
> >AM> myvalue: myblock/1/2/3
> >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
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 [
forall c [
if all [block? d: first c d: deepfind d v] [
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!