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

Programatically creating layouts

 [1/8] from: andy:flyingcat at: 9-Sep-2002 13:02


Hi: 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 :-) 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. A simple example might explain the problem better: ------------------------ REBOL [ ] test_list: [ "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 "bn-01" append mygrid [btn] append mygrid title append mygrid [with] tmp: compose [grid_time: time] append mygrid [tmp] ] grid-f: layout load mygrid print mold mygrid halt ---- The above example doesn't work. It results in a [ ... btn 0:30 with tmp] I'm trying to load the btn/grid-time with the times from the test_list. As far as I know, that means I use 'with . So I'm trying to get the proper block created to load. If I don't put [ ] around tmp, the statement contained within tmp gets evaluated , and I lose the "grid_time: " part of it. If I do put [ ] around tmp, I end up with [with tmp] which means that I end up evaluating tmp at load time, so every entry ends up with the same time. I'm sure there's some combination of compose, join, and reduce that will give the right results....can anyone point me in the right direction ? Thanks, Andy

 [2/8] 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

 [3/8] from: rotenca:telvia:it at: 9-Sep-2002 20:20


Hi, REBOL [ ] test_list: ["name of title" 00:30 ] mygrid: [ style btn button with [grid-offset: none grid_time: none] ] grid_count: 0 foreach [title time] test_list [ insert tail mygrid compose/deep [ bn-01: btn (title) with [grid_time: (time)] ] ] grid-f: layout mygrid print mold mygrid halt Compose evaluates the paren expressions. Compose/deep evaluates the paren expressions also in the inner blocks. Hope this helps --- Ciao Romano

 [4/8] from: andy:flyingcat at: 9-Sep-2002 14:15


Hmm, I might be catching on. I tried a couple more things, and this one seems to do what I want... Andy ------------------------ REBOL [ ] test_list: [ "name of title" 00:30 ] mygrid: [style btn button with [grid-offset: none grid_time: none] ] grid_count: 0 foreach [title time ] test_list [ append mygrid "bn-01" append mygrid [btn] append mygrid title append mygrid [with] append mygrid reduce [join compose [grid_time: ] time ] ] grid-f: layout load mygrid print mold mygrid halt

 [5/8] from: andy:flyingcat at: 9-Sep-2002 15:24


Ah, so _that's_ what the help on compose/deep means! Thanks, this looks like the technique I was looking for; I can make the expressions as complicated as necessary now. Andy

 [6/8] from: andy:flyingcat at: 9-Sep-2002 15:49


Thanks; the nesting of the reduces combined with the to set-word wasn't quite obvious to me :-) Andy --- 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

 [7/8] from: g:santilli:tiscalinet:it at: 9-Sep-2002 21:55


Hi Andy, On Monday, September 9, 2002, 7:02:02 PM, you wrote: AF> My question today is one relating to variable scoping, basically. Then you'll be a bit surprised, when you'll discover that the concepts of "variable" and "scoping" don't make much sense with REBOL. :-) However, your problem can be solved without having to discuss variable scoping at all. ; channel was missing in your example, i think. I just added ; a dummy item... test_list: [channel "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 "bn-01" ?? append mygrid 'btn append mygrid title append mygrid 'with append/only mygrid compose [grid-time: (time)] ] grid-f: layout mygrid Here I get: == [style btn button with [grid-offset: none grid_time: none] btn "name of title" with [grid-time: 0:30]] which I think is what you wanted to do. It can be done in other ways too, but I didn't want to change your original too much, in the hope that it can be a little more understandable this way. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [8/8] from: andy::flyingcat::com at: 9-Sep-2002 23:39


> On Behalf Of Gabriele Santilli >> AF> My question today is one relating to variable scoping, basically. > > Then you'll be a bit surprised, when you'll discover that the > concepts of "variable" and "scoping" don't make much sense with > REBOL. :-) However, your problem can be solved without having to > discuss variable scoping at all.
I knew that, actually :-) I couldn't think of a better way to describe it, though.
> ; channel was missing in your example, i think. I just added > ; a dummy item... > test_list: [channel "name of title" 00:30 ]
Yes, it was; I was cutting down a larger program into a small example.
> mygrid: [style btn button with [grid-offset: none grid_time: none] ] > grid_count: 0
<<quoted lines omitted: 7>>
> grid-f: layout mygrid > Here I get:
The append/only is a useful trick. I had tried to get the same effect with append to-block. The fact that parens are evaluated within compose blocks was the piece I was missing. Thanks, Andy

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted