[REBOL] Re: Programatically creating layouts
From: greggirwin:mindspring at: 9-Sep-2002 12:09
Hi Andy,
<< Thanks for all the help so far. I look forward to the day when this
becomes natural, and I can start answering questions, rather than asking
them all the time :-) >>
I'm sure it won't be long. :)
<< My question today is one relating to variable scoping, basically. I'm
creating layouts dynamically, from tables and files. So I'm creating a
big block, containing my layout definition (using append). I'm running
into a problem, where part of the statement needs to be evaluated at the
time of the append, and part needs to be evaluated when the layout is
loaded. >>
I made some assumptions when putting this together, so let me know how far
off the mark it is:
; Added channel ("04") - GSI
test_list: ["04" "name of title" 00:30 ]
mygrid: [style btn button with [grid-offset: none grid_time: none]]
grid_count: 0
foreach [channel title time ] test_list [
append mygrid compose/deep [
(to set-word! 'bn-01) btn (title) with [grid_time: (time)]
]
]
grid-f: layout load mygrid
print mold mygrid
COMPOSE is really super darn handy for stuff like this, but you could also
do it with REDUCE:
test_list: ["04" "name of title" 00:30 ]
mygrid: [style btn button with [grid-offset: none grid_time: none]]
grid_count: 0
foreach [channel title time ] test_list [
append mygrid reduce [
to set-word! 'bn-01 'btn title 'with reduce [to set-word! 'grid_time
time]
]
]
grid-f: layout load mygrid
print mold mygrid
REBOL gives you lots of flexibility to do things the way that seems best in
different contexts (pun intended). Sometimes one syntax or another will help
to make it clear which parts of a block are static and which are dynamic; to
make things as uncluttered as possible; or that give the best representation
of what the output should look like.
HTH!
--Gregg