Block member as a mutable variable (question)
[1/4] from: tim::johnsons-web::com at: 11-Sep-2001 8:55
Thanks to Carl and Joe Neely. Your explanations
are very clear.
regards
tim
[2/4] from: tim:johnsons-web at: 10-Sep-2001 22:11
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?
TIA
Tim
[3/4] 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"]
<<quoted lines omitted: 11>>
> 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
[4/4] 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"]
<<quoted lines omitted: 11>>
> 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
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted