REBOL scheme: how to automatically create layout words - does the word have no context?

Using REBOL / View 2.7.8 Core, I would like to prepare a presentation layout in advance, automatically assigning words to various layout elements, as in the following example. Instead

prepared-view: [across cb1: check label "Checkbox 1" cb2: check label "Checkbox 2" cb3: check label "Checkbox 3" cb4: check label "Checkbox 4" ] view layout prepared-view 

I would like the words cb1 thru cb5 created automatically, for example:

 prepared-view2: [ across ] for i 1 4 1 [ cbi: join "cb" i cbi: join cbi ":" cbi: join cbi " check" append prepared-view2 to-block cbi append prepared-view2 [ label ] append prepared-view2 to-string join "Checkbox " i ] view layout prepared-view2 

However, while the difference prepared-view prepared-view2 shows the difference is not in the analyzed block ( == [] ), the second script leads to an error:

  ** Script Error: cb1 word has no context ** Where: forever ** Near: new/var: bind to-word :var :var 

I spent hours trying to understand why, and I think that somehow new words should be tied to a specific context, but I have not yet found a solution to the problem.

What do I need to do?

+7
rebol rebol3 rebol2
source share
2 answers
 bind prepared-view2 'view view layout prepared-view2 

creates the correct bindings.

And here's another way to create layouts dynamically

 >> l: [ across ] == [across] >> append l to-set-word 'check == [across check:] >> append l 'check == [across check: check] >> append l "test" == [across check: check "test"] >> view layout l 

And then you can use loops to create different variables to add to your layout.

+2
source share

When you use TO-BLOCK to convert a string to a block, it is a low-level operation that does not go through the โ€œnormalโ€ default context binding. All words will be unrelated:

 >> x: 10 == 10 >> code: to-block "print [x]" == [print [x]] >> do code ** Script Error: print word has no context ** Where: halt-view ** Near: print [x] 

Therefore, when you want to create code from raw strings at runtime whose search queries will work, one option is to use LOAD, and it will do something by default, and this may work for some code (the loader is this, how the bindings were made for the code you use that came from the source):

 >> x: 10 == 10 >> code: load "print [x]" == [print [x]] >> do code 10 

Or you can explicitly specify contexts / objects (or by means of an example word tied to this context) and use BIND.

+2
source share

All Articles