Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: initializing View with an array
Pages: [1] Print
Author Topic: initializing View with an array  (Read 749 times)
SituAgent
Newbie
*
Offline Offline

Posts: 7


View Profile
initializing View with an array
« on: November 28, 2006, 06:03:38 PM »

     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
== 400x400

CODE

view layout/size [
     for index 1 agentMax 1 [
          origin (agent/index/2) box (agent/index/1) cellSize
         ]
    ] gridSize

ERRORS

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
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: initializing View with an array
« Reply #1 on: November 29, 2006, 01:42:50 AM »

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
Newbie
*
Offline Offline

Posts: 34


View Profile WWW
Re: initializing View with an array
« Reply #2 on: November 29, 2006, 02:52:14 AM »

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).


Code:
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
Newbie
*
Offline Offline

Posts: 7


View Profile
Re: initializing View with an array
« Reply #3 on: November 29, 2006, 05:27:33 PM »

     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
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: initializing View with an array
« Reply #4 on: November 29, 2006, 09:11:22 PM »

My example didn't use reduce or compose .. I think it works without 'compose.

It used repend, which is append while reducing  Grin

if 'index is used in a path as you did, you have to force the evaluation using :index ...
Logged

SituAgent
Newbie
*
Offline Offline

Posts: 7


View Profile
Re: initializing View with an array
« Reply #5 on: November 29, 2006, 11:33:40 PM »

My example didn't use reduce or compose .. I think it works without 'compose.

It used repend, which is append while reducing  Grin

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
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: initializing View with an array
« Reply #6 on: November 30, 2006, 02:08:42 AM »

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
Newbie
*
Offline Offline

Posts: 7


View Profile
Re: initializing View with an array
« Reply #7 on: November 30, 2006, 12:46:49 PM »

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
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: initializing View with an array
« Reply #8 on: November 30, 2006, 06:14:26 PM »

Quote
>> 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
Newbie
*
Offline Offline

Posts: 7


View Profile
Re: initializing View with an array
« Reply #9 on: November 30, 2006, 07:27:13 PM »

     Yes, thanks.  I've been experimenting, and you've given me more examples to play with.

     Much obliged. Wink
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: initializing View with an array
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 02, 2008, 06:53:41 AM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2311 Posts in 595 Topics by 4139 Members
Latest Member: DietaVato

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc