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

[REBOL] Re: Block member as a mutable variable (question)

From: joel:neely:fedex at: 11-Sep-2001 1:26

Hi, Tim, Tim Johnson wrote:
> I have a nested block as such: > file-block: [[0 ["recno" "integer"] ["name" "string"] > ["country" "string"] ["speed" "integer"] ["range" "integer"]]] > I set a word to the numeric value like this: > >> test: first first file-block > == 0 > Then I increment test: > >> test: test + 1 > == 1 > <sigh>but</sigh> I don't get the results I want. > >> file-block > == [[0 ["recno" "integer"] ["name" "string"] ["country" "string"] > ["speed" "integer"] ["range" "integer"]]] > Alas! I was hoping that I would see a '1 as first first 'file-block > What have I left out here? >
Carl Read has already hit the key issue. REBOL knows about references only in connection with certain data types (e.g. any block-like type). If you want a reference to a "place" where an integer is held, you'll have to keep up with that place explicitly. That said, another couple of ways to do what I think you want would be:
>> file-block: [[0 ["recno" "integer"] ["name" "string"]
[ ["country" "string"] ["speed" "integer"] ["range" integer ]]] == [[0 ["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" integer ]]]
>> file-block/1/1: file-block/1/1 + 1
== [1 ["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" "integer"]]
>> file-block
== [[1 ["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" integer ]]]
>> blk1: first file-block
== [1 ["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" "integer"]]
>> blk1/1: 1 + first blk1
== [2 ["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" "integer"]]
>> file-block
== [[2 ["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" integer ]]] That is, access the "place" where the integer lives either in terms of its entire path relative to FILE-BLOCK, or make a reference to the smallest block containing that integer and refer to the "place" in *that* container. HTH! -jn- -- ------------------------------------------------------------ Programming languages: compact, powerful, simple ... Pick any two! joel'dot'neely'at'fedex'dot'com