Reputation: 16321
I have this code:
REBOL [Title: "Employee list"]
screen1: does [
emp-list: [
"Amy" 1
"Bob" 2
"Carrie" 3
]
gui-layout: [ text "click your name" ]
foreach [emp-name emp-id] emp-list [
append gui-layout compose/deep [
box (emp-name) [screen2 (emp-id)]
]
]
view layout gui-layout
]
screen2: func [emp-id] [
choice-list: [
"A" 11
"B" 22
]
gui-layout: [
box "<-- back to names" [screen1]
text reform ["clicked id " emp-id ", now choose below"]
]
foreach [choice-name choice-id] choice-list [
append gui-layout compose/deep [
box (choice-name) [print [(emp-id) (choice-id)]]
]
]
view layout gui-layout
]
screen1
Now, if you click someone then click 'back', the menu grows. (And if you click someone else, the second menu has grown too.) One workaround(?) I've found is to put clear emp-list
before view layout gui-layout
to fix the first screen from doing this. Yet, if I print emp-list
in there I can see that it's not emp-list
that is growing. How can this be?
Upvotes: 1
Views: 82
Reputation: 4886
You're using a persistence feature of functions.
See
persist: has [ a ] [ a: [] append a random 100 print a ]
no-persist: has [ a ] [ a: copy [] append a random 100 print a ]
To do what you want, put a 'copy before each series you're appending to
gui-layout: copy [ text "click your name" ]
and
gui-layout: copy/deep [
box "<-- back to names" [screen1]
text reform ["clicked id " emp-id ", now choose below"]
]
Upvotes: 4