|
Pages: [1]
|
 |
|
Author
|
Topic: initializing View with an array (Read 749 times)
|
|
SituAgent
|
I am a REBOL newbie trying to initialize arbitrary locations on a View grid using an array. There is a simple example below, but I've tried dozens of variations including attempts to use COMPOSE. It seems odd that such a simple concept would be difficult, so I appreciate any suggestions. Thanks. David
VALUES >> agentMax == 11 >> agent == [[0.255.0 0x0] [0.255.0 0x160] [0.255.0 80x0] [0.255.0 80x80] [0.255.0 80x240] [0.255.0 1 60x0] [0.255.0 160x80] [0.0.255 160x240... >> cellSize == 80x80 >> gridSize == 400x400CODE view layout/size [ for index 1 agentMax 1 [ origin (agent/index/2) box (agent/index/1) cellSize ] ] gridSizeERRORS Unknown word or style: for Unknown word or style: index Misplaced item: 1 Unknown word or style: agentMax Misplaced item: 1 Misplaced item: [ origin (agent/index/2) box (agent/index/1) cellSize]
|
|
|
|
|
Logged
|
|
|
|
|
Graham
|
It won't work as you have shown it because the words inside the layout block are not Rebol, but the VID dialect.
Layout has a parser which tries to interpret the rebol code inside the block, and finds none that is consistent with the VID dialect.
Something like this might work .. untested.
mylayout: [ ]
for i 1 AgentMax 1 [ repend mylayout [ 'at agent/:i/2 'box agent/:i/1 cellsize ] ]
view layout/tight/size center-face mylayout gridsize
|
|
|
|
|
Logged
|
|
|
|
|
Philippe
|
Hello, layout function wait a block with specific keywords. These keywords (origin, ..) must only be used inside the VID dialect. So, you must *compose* the block before pass it to 'layout. See below (be careful with 'reduce and keywords as 'words). agentMax: 8 agent: [[0.255.0 0x0] [0.255.0 0x160] [0.255.0 80x0] [0.255.0 80x80] [0.255.0 80x240] [0.255.0 160x0] [0.255.0 160x80] [0.0.255 160x240]] cellSize: 80x80 gridSize: 400x400
mylayout: copy []
for index 1 agentMax 1 [ append mylayout reduce compose ['origin (agent/:index/2) 'box (agent/:index/1) cellSize] ]
view center-face layout/tight/size mylayout gridSize
===Philippe
|
|
|
|
|
Logged
|
===Philippe
|
|
|
|
SituAgent
|
Thank you for your assistance; the code works fine now. Is there somewhere in the documentation (that I missed) that explains how 'reduce' and 'compose' work together?
Also, when would one use 'index' versus ':index'? It seems like both forms return the value to which 'index is bound.
Thanks again.
David
|
|
|
|
|
Logged
|
|
|
|
|
Graham
|
My example didn't use reduce or compose .. I think it works without 'compose. It used repend, which is append while reducing  if 'index is used in a path as you did, you have to force the evaluation using :index ...
|
|
|
|
|
Logged
|
|
|
|
|
SituAgent
|
My example didn't use reduce or compose .. I think it works without 'compose. It used repend, which is append while reducing  if 'index is used in a path as you did, you have to force the evaluation using :index ... Thanks for explaining repend. I will continue to experiment with the techniques that you've suggested. If you don't force a variable in a path, will Rebol/View treat is literal (unevaluated)?
|
|
|
|
|
Logged
|
|
|
|
|
Graham
|
There are two types of paths
if you have this a/b/c, then Rebol looks for a path inside the object 'a.
if you want the c'th item in 'b, then you have to do this a/b/:c
or, a/b/3 where c = 3.
Since words can not be numbers, the latter case is unambiguous.
If c is 3, and you do this .. a/b/c, then an error will be produced if 'c does not exist.
Rebol doesn't evaluate words in the path unless told to using parens etc.
I hope I haven't confused you ...
|
|
|
|
|
Logged
|
|
|
|
|
SituAgent
|
There are two types of paths
if you have this a/b/c, then Rebol looks for a path inside the object 'a.
if you want the c'th item in 'b, then you have to do this a/b/:c
or, a/b/3 where c = 3.
Since words can not be numbers, the latter case is unambiguous.
If c is 3, and you do this .. a/b/c, then an error will be produced if 'c does not exist.
Rebol doesn't evaluate words in the path unless told to using parens etc.
I hope I haven't confused you ...
On the contrary, your clarification is quite helpful. Do I understand correctly that one needs the colon only for the variable that is the last (lowest) step on the path? Thanks. David
|
|
|
|
|
Logged
|
|
|
|
|
Graham
|
>> o: make object! [ a: none b: 1 c: make object! [ d: 2]] >> e: 'c == c >> o/:e/d == 2 >> o/e/d ** Script Error: Invalid path value: e ** Near: o/e/d
Does that help?
|
|
|
|
|
Logged
|
|
|
|
|
SituAgent
|
Yes, thanks. I've been experimenting, and you've given me more examples to play with. Much obliged. 
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |
News: 01-09-08 Alpha version of REBOL 3 has been released!
2311 Posts in 595 Topics by 4139 Members
Latest Member: DietaVato
|