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: carl:cybercraft at: 11-Sep-2001 19:10

Hi Tim - Carl here again... On 11-Sep-01, 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?
Integers aren't mutable, and you'll find that your test variable is an integer and not a reference to a value in file-block (which I think is what you expected?) My approach would be...
>> test: first file-block
== [0 ["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" "integer"]]
>> change test 1 + first test
== [["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" "integer"]]
>> test
== [1 ["recno" "integer"] ["name" "string"] ["country" "string"] ["speed" "integer"] ["range" "integer"]] The above looks a bit back-to-front, but... change test first test + 1 gives an error, though you could use... change test test/1 + 1 which is perhaps the nicest. Hope that helps.
> TIA > Tim
-- Carl Read