我有这个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。我在这里做错了什么?
答案 0 :(得分:2)
>> probe gui-layout
[text "click to reveal number"
box name [print id]
box name [print id]
box name [print id]
]
Rebol只需将行box name [print id]
附加到'gui-layout
,而不进行评估,
在FOREACH循环之后,'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]
]