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

[REBOL] Re: Just two ways to the same place?

From: moliad::gmail::com at: 30-Aug-2007 0:11

just for the exercise, here is your previous script using anonymous context. In such an example its not super usefull, but gives the idea. its often used when people define libs, where they want to protect the internals from accidental tampering... and some developers do not like the path notation or object/method concept, so they put their code in the global namespace on purpose, for no other reason than not having to type lib/function all the time. good and bad... depends on size and scope of your project... especially when several people and parts are intertwined... in the following, the only way to tamper with c is to actually modify (using change or insert for example on second :m1c ) or somehow copy & rebind part of the m1c function body... but all of this is pretty advanced and is only going to be done on purpose... so bottom line, it does protect your code from "unintentional" havoc, but real malicious tampering is not really preventible. rebol [] ;---------------------------------------------- selector: center-face layout [ btn "Module 1" [ unview view/new module-1 ] btn "Module 2" [ unview view/new module-2 ] ; btn "# of calls to Module 1" [ m1c ] btn "# of calls to Module 2" [ m2c ] ] ;---------------------------------------------- context [ c: 0 set 'm1c does [ notify form c ] set 'module-1 does [ center-face layout [ text "Module #1" btn "Back" [ c: c + 1 unview view/new selector ] ] ] ] ;---------------------------------------------- context [ c: 0 set 'm2c does [ notify form c ] set 'module-2 does [ center-face layout [ text "Module #2" btn "Back" [ c: c + 1 unview view/new selector ] ] ] ] ;---------------------------------------------- view selector ;-------------------- EoS ---------------------