[REBOL] Re: Nested blocks - retrieving and setting with variables
From: gabriele::colellachiara::com at: 27-Sep-2004 18:50
Hi Charles,
On Friday, September 24, 2004, 7:30:14 AM, you wrote:
C> I want to set one value within one of the nested blocks to another value.
C> However, i and j are variable, and this is looped, and I need to modify i
C> and j in the process of using them. For instance, this is what I've got
C> right now, and I really don't like it:
C> do rejoin compose ["matrix/" (i + 1) "/" (j + 1) ": " x]
Given:
m-pick:
func [series indexes] [
foreach index reduce indexes [series: pick series index]
]
m-poke:
func [series indexes data /local lst] [
indexes: reduce indexes
lst: last indexes
remove back tail indexes
foreach index indexes [series: pick series index]
poke series lst data
]
you can then:
>> m-poke matrix [i + 1 j + 1] x
== 5
>> matrix
== [[0 1 2 3 4] [1 0 0 0 0] [2 0 0 5 0]]
C> Also, I get x by comparing a couple values within matrix. For instance,
C> in another language I work in that's C-like:
C> min(mtx[si][ti + 1] + 1, mtx[si + 1][ti] + 1, mtx[si][ti] + cost);
minimum-of reduce [
1 + m-pick matrix [si ti + 1]
1 + m-pick matrix [si + 1 ti]
cost + m-pick matrix [si ti]
]
which maybe is even more readable.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/