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

[REBOL] another gotcha

From: pat665:ifrance at: 2-Dec-2001 12:04

Hi all, Here is another gotcha from rebol I found as I was cleaning up some of my code. This cleaning job was motivated by the following section of the "view user's guide". [... 13.3. Avoiding Variable Collisions For large scripts that have a lot of position and face variables, it may become difficult to manage all of the names and keep them from interfering with each other. A simple solution to this problem is to define pages within objects that have the required variables defined locally to the objects. For instance here is an address book form that keeps all of its variables local: ...] Sounds like a good idea because I had a lot of stuff in my layout. My first attempt was like this : Rebol [] o-win: make object! [ page: layout [ banner "Gotcha !" zone: banner "rebol" ] ] o-win/page/zone/text: "right" show o-win/page/zone view center-face o-win/page The result was this : ** Script Error: Invalid path value: zone ** Where: do-boot ** Near: o-win/page/zone/text: "right" My second attempt was like this, and it works, and I was not happy with it because what is the point of making an object if it works that way too! Rebol [] o-win: make object! [ page: layout [ banner "Gotcha !" zone: banner "rebol" ] ] zone/text: "oops" show zone view center-face o-win/page I thought that making an object would protect "zone" from being modified from the outside. Thanks to Ladislav, I understand that it was time to re-read the documentation to search for the little tiny detail I must have missed. And I found it, "zone" needed a declaration like this : o-win: make object! [ zone: none page: layout [ banner "Gotcha !" zone: banner "rebol" ] ] After that, direct access to zone produce an error (as expected) ** Script Error: zone has no value ** Where: do-boot ** Near: zone/text: "oops" So the final attemp (that was successful) was : Rebol [] o-win: make object! [ zone: none page: layout [ banner "Gotcha !" zone: banner "rebol" ] ] o-win/zone/text: "right" show o-win/zone view center-face o-win/page But finally the big question is why-why-why ? As I perceive it (in my case perceive is more appropriate than understand) the page's zone needs a holder (the "zone: none") in the object. I have tried to make an explicit holder instead and it works too : Rebol [] o-win: make object! [ explicit-holder: none page: layout [ banner "Gotcha !" zone: banner "rebol" do [explicit-holder: get 'zone] ] ] o-win/explicit-holder/text: "foo" show o-win/explicit-holder view center-face o-win/page Has anyone a good explanation for this ?