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

[REBOL] Re: An array of objects?

From: rebol:techscribe at: 21-Dec-2000 18:27

Vache, the reason you are having problems is because of the set-word notation you are using and the fact that you are not reducing your block. Here's what I mean: 1. reducing the block: block: [ make object! [ directions: [0 1 0 1] description: "You are in a dark cave." ] ]  What do you have here? You do not have a block consisting of an object! You have a block consisting of the words make object! and an embedded block consisting of the words directions and description, the block [0 1 0 1] and the string "You are in a dark cave.". The length of block is 3, namely the word make, the word object! and the block containing the values you intend for the object:
>> length? block
== 3 Also try
>> first block
== make
>> second block
== object!
>> third block
== [ directions: [0 1 0 1] description: "You are in a dark cave." ] Compare to: block: reduce [ make object! [ directions: [0 1 0 1] description: "You are in a dark cave." ] ] REBOL will first reduce the block, which means that it evaluates the contents of the block. The reduce function returns a block that contains the evaluated contents of the block it was passed. The word block now references a block that indeed contains an object as you intended.
>> length? block
== 1
>> type? first block
== object! 2. The set-word problem. Now, let's assume you were to use the following code (Note that I added reduce to your first first line): REBOL [] world: make block! reduce [ room1: make object! [ directions: [0 1 0 1] ; N S E W description: "You are in a dark cave!" ] room2: make object! [ directions: [1 0 0 1] description: "You are outside!" ] ] What you now have are two global words called room1 and room2. The block referenced by world now looks like this:
>> print mold world
[ make object! [ directions: [0 1 0 1] description: "You are in a dark cave." ] make object! [ directions [1 0 0 1] description: "You are outside." ] ] What's changed? The two set-words room1 and room2 are no longer contained in the block. You can now access the block as world/1/directions world/1/description world/2/directions world/2/description Hope this helps, Elan Vache wrote: