0

I have this REBOL script:

REBOL [Title: "Employee list"]

emp-list: [
    "Amy" 1
    "Bob" 2
    "Carrie" 3
]

gui-layout: [ text "click to reveal number" ]

foreach [name id] emp-list [
    append gui-layout [
        box name [print id]
    ]
]

view layout gui-layout

Strangely, to me, it makes a window with three Carries which print 3 when clicked. What am I doing wrong here?

Kev
  • 15,899
  • 15
  • 79
  • 112

1 Answers1

2
>> probe gui-layout

[text "click to reveal number"
box name [print id]
box name [print id]
box name [print id]
]

Rebol simply appends the line box name [print id] to 'gui-layout, without evaluating it, after the FOREACH loop, 'name points to "Carrie" and 'id points to 3.

So to avoid this, you can replace the FOREACH loop like this:

foreach [name id] emp-list [
    append gui-layout compose/deep [
        box (name) [print (id)]
    ]
]

and after this loop:

>> probe gui-layout

[text "click to reveal number"
box
"Amy" [print 1]
box
"Bob" [print 2]
box
"Carrie" [print 3]
]
WuJian
  • 56
  • 1
  • Super! I was noticing that if I put a print statement in the loop it printed correctly but still didn't make the buttons right. Wasn't sure where to dig next. Thanks! – Kev Oct 05 '12 at 12:58