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

Nested blocks - retrieving and setting with variables

 [1/8] from: chalz:earthlink at: 24-Sep-2004 1:30


Howdy. First post in a long time; haven't been playing with REBOL much. However, I have a problem I wanted to handle in REBOL, and I'm kind of stuck at a point. Consider: matrix: [[0 1 2 3 4] [1 0 0 0 0] [2 0 0 0 0]] i: 2 j: 3 x: 5 I want to set one value within one of the nested blocks to another value. However, i and j are variable, and this is looped, and I need to modify i and j in the process of using them. For instance, this is what I've got right now, and I really don't like it: do rejoin compose ["matrix/" (i + 1) "/" (j + 1) ": " x] Also, I get x by comparing a couple values within matrix. For instance, in another language I work in that's C-like: min(mtx[si][ti + 1] + 1, mtx[si + 1][ti] + 1, mtx[si][ti] + cost); Shy of using 'pick' a dozen times, or compose like above, anyone have recommendations as to how best (simplest) to do that? I know I can do matrix/:i/:j But I can't do math on the variables there. Suggestions? Thanks. --Charles

 [2/8] from: carl:cybercraft at: 24-Sep-2004 18:01


On Friday, 24-September-2004 at 1:30:14 you wrote,
> Howdy. First post in a long time; haven't been playing with REBOL much. >However, I have a problem I wanted to handle in REBOL, and I'm kind of stuck
<<quoted lines omitted: 16>>
>matrix/:i/:j > But I can't do math on the variables there. Suggestions? Thanks.
How about... poke pick matrix i + 1 j + 1 x ? -- Carl

 [3/8] from: chalz::earthlink::net at: 24-Sep-2004 3:45


> How about... > > poke pick matrix i + 1 j + 1 x
Okay, that's very cool. However, how about:
>> min(mtx[si][ti + 1] + 1, mtx[si + 1][ti] + 1, mtx[si][ti] + cost);
Am I doomed to do something like: x: (first at pick matrix si ti + 1) + 1 y: (first at pick matrix si + 1 ti) + 1 z: matrix/:si/:ti + cost poke pick matrix si + 1 ti + 1 first minimum-of reduce [x y z] ? Or am I making life overly complicated for myself? Thanks again. --Charles

 [4/8] 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/

 [5/8] from: lmecir::mbox::vol::cz at: 28-Sep-2004 7:57


Charles napsal(a):
> Okay, that's very cool. However, how about: >>>min(mtx[si][ti + 1] + 1, mtx[si + 1][ti] + 1, mtx[si][ti] + cost);
<<quoted lines omitted: 8>>
> Thanks again. >--Charles
Carl Sassenrath has decided (at the Collaboration Conference), that we will be able to use: min min mtx/(si)/(ti + 1) + 1 mtx/(si + 1)/(ti) + 1 mtx/(si)/(ti) + cost how would that work for you? -L

 [6/8] from: chalz:earthlink at: 28-Sep-2004 2:25


>>>>min(mtx[si][ti + 1] + 1, mtx[si + 1][ti] + 1, mtx[si][ti] + cost); > Carl Sassenrath has decided (at the Collaboration Conference), that we > will be able to use: > > min min mtx/(si)/(ti + 1) + 1 mtx/(si + 1)/(ti) + 1 mtx/(si)/(ti) + > cost > > how would that work for you?
I think that would be incredible. Ever since I started working in REBOL, accessing and manipulating values within a series have always been problems for me. I'm so used to the array[index] format. Hah, course, there's another language, a game language, I've toyed with which allows access such as: array[1..$] array[3..$-5] etc, where '$' represents the end of the array, and '..' is, in case you haven't guessed, "all values between the specified values, inclusive". So [1..$] with an array that contains 10 values would be all values from array[1] to array[10]. This is most useful for working backwards or selecting portions of an array (data = source[4..$]; tag = source[$-3..$]; and so forth). That spoiled me quickly. Anyways, that's interesting news. And I hadn't thought of using 'min min'.. saves me the hassle of reduce and pick.. Like I said, I'm rusty. Thanks all. --Charles

 [7/8] from: lmecir::mbox::vol::cz at: 28-Sep-2004 13:53


Charles napsal(a):
>> <>min min mtx/(si)/(ti + 1) + 1 mtx/(si + 1)/(ti) + 1 mtx/(si)/(ti) + >> cost >>
....
>> <> I think that would be incredible... >
....
>> <>Hah, course, there's >> another language, a game language, I've toyed with which allows
<<quoted lines omitted: 11>>
>> source[$-3..$]; >> and so forth). That spoiled me quickly.
this is a different cause. Maxim wanted to have such a syntax too, but a Rebol dialect: copy-array [-3 - tail head - 2] looks better to me. In case you need it there is a lot of people able to write such a dialect including myself. Rebol ask for more. -L

 [8/8] from: chalz::earthlink::net at: 28-Sep-2004 12:03


>>> array[1] to array[10]. This is most useful for working backwards or >>> selecting portions of an array (data = source[4..$]; tag
<<quoted lines omitted: 6>>
> looks better to me. In case you need it there is a lot of people able to > write such a dialect including myself. Rebol ask for more.
As far as I'm concerned, no, I really should just learn, once and for all, how to use series properly. And learn parse and dialects properly, too. Even if they should drive me insane - who'll notice? Thanks for all the assistance. I'm sure I'll be back. :) --Charles

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted