Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Confused over Contexts

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 ... > > rebol [] > fn-win: func [/local lv-fld] > [ > view/new layout > [ > lv-fld: field > button "Value" [print lv-fld/text] > ] > ] >
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 > [ > 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 >
-Volker