Confused over Contexts
[1/5] from: philb::upnaway::com at: 22-Dec-2001 17:37
Hi Guys,
I have a simple progam ...
rebol []
fn-win: func [/local lv-fld]
[
view/new layout
[
lv-fld: field
button "Value" [print lv-fld/text]
]
]
main: view layout
[
button "Window" [fn-win]
]
1. Run program to open Window #1
2. Press button to open a Window #2
3. On Window #2, Enter "AAAA"
4. Press Button on window #2
5. Program prints "AAAA"
6. Press button on Window #1 to Open Window #3
7. On Window #3, Enter "BBBB"
8. Press Button on Window #3
9. Program prints "BBBB"
10. Press Button on Window #2 (again)
11. Prigram prints "BBBB"
:-(
Even though I declare lv-fld as local the there only seems to be 1 version of lv-face
??
Is there a simple solution to this problem ?
Cheers Phil
[2/5] from: nitsch-lists:netcologne at: 22-Dec-2001 15:37
RE: [REBOL] Confused over Contexts
[philb--upnaway--com] wrote:
> Hi Guys,
> I have a simple progam ...
<<quoted lines omitted: 7>>
> ]
> ]
fn-win: func []
[
context[
lv-fld: none
view/new layout
[
lv-fld: field
button "Value" [print lv-fld/text]
]
]
]
difference is, functions share the context for their locals,
only saving/restoring content for recursion.
so if a function gives a word to the outside,
all blocks share the same word.
with context a real new word is created each time.
also RT says they may cange function-behavior,
setting all locals to none on return.
so using locals in code which "lives" after return may break then.
> main: view layout
> [
<<quoted lines omitted: 15>>
> Is there a simple solution to this problem ?
> Cheers Phil
-Volker
[3/5] from: rotenca:telvia:it at: 22-Dec-2001 19:28
Hi Volker
> difference is, functions share the context for their locals,
> only saving/restoring content for recursion.
<<quoted lines omitted: 4>>
> setting all locals to none on return.
> so using locals in code which "lives" after return may break then.
I think that in this case 'context works only because layout reduce the
action
block. In other cases, the fact that none of func, use, context duplicate the
body, would take to shared context.
---
Ciao
Romano
[4/5] from: nitsch-lists:netcologne at: 22-Dec-2001 21:15
RE: [REBOL] Re: Confused over Contexts
[rotenca--telvia--it] wrote:
> Hi Volker
> > difference is, functions share the context for their locals,
<<quoted lines omitted: 9>>
> block. In other cases, the fact that none of func, use, context duplicate the
> body, would take to shared context.
yes, the block is copied by layout.
otherwise it would be [context copy/deep [..]]
but the point is, all this copied blocks use the same local words
in the same context.
so one needs to create a new context for each layout.
> ---
> Ciao
> Romano
>
-Volker
[5/5] from: philb:upnaway at: 24-Dec-2001 8:18
Hi Volker,
Excellent .... this solves another long term bug in my Mailer.
Cheers Phil
p.s. Merry Xmas to everyone on the Rebol Mailing list
=== Original Message ===
RE: [REBOL] Confused over Contexts
[philb--upnaway--com] wrote:
> Hi Guys,
> I have a simple progam ...
<<quoted lines omitted: 7>>
> ]
> ]
fn-win: func []
[
context[
lv-fld: none
view/new layout
[
lv-fld: field
button "Value" [print lv-fld/text]
]
]
]
difference is, functions share the context for their locals,
only saving/restoring content for recursion.
so if a function gives a word to the outside,
all blocks share the same word.
with context a real new word is created each time.
also RT says they may cange function-behavior,
setting all locals to none on return.
so using locals in code which "lives" after return may break then.
> main: view layout
> [
<<quoted lines omitted: 15>>
> Is there a simple solution to this problem ?
> Cheers Phil
-Volker
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted