Search code examples
user-interfacered-lang

Adding GUI items from a series in Red Language


I want to add GUI items from a series. I am trying following code but it does not work:

mylist: ["first" "second" "third" "fourth" ]

view[
    foreach i mylist [
        text i  ]]

The error is:

*** Script Error: VID - invalid syntax at: [foreach ll mylist]
*** Where: do
*** Stack: view layout cause-error 

Where is the problem and how can it be solved? Thanks for your answers.


Solution

  • Remember that...

    view [... what goes in here...]
    

    ...is a dialect, it is not regular code. It's a special dialect that has some evaluative qualities, but the normal rules don't always apply.

    Don't forget that a dialect is just a block of values like anything else in Red. You can pre-build it as such:

    view collect [
        foreach i mylist [
            keep 'text keep i
        ]
    ]
    

    You can stick a PROBE between VIEW and COLLECT there to see what you're generating and COLLECT/KEEP gives you a lot of scope for tuning the values that end up in your view spec.