0

我有这个 REBOL 脚本:

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

奇怪的是,对我来说,它会创建一个包含三个 Carries 的窗口,单击时会打印 3 个。我在这里做错了什么?

4

1 回答 1

2
>> probe gui-layout

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

Rebol 只是在 FOREACH 循环之后将行附加box name [print id]'gui-layout,而不对其进行评估,'name指向"Carrie"'id指向 3。

因此,为避免这种情况,您可以像这样替换 FOREACH 循环:

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

在这个循环之后:

>> probe gui-layout

[text "click to reveal number"
box
"Amy" [print 1]
box
"Bob" [print 2]
box
"Carrie" [print 3]
]
于 2012-10-05T04:22:36.400 回答