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

[REBOL] Re: Namespaces for functions

From: joel:neely:fedex at: 28-Aug-2001 11:59

Hi, Gregg, My preference (which I've seen in many posts from others to the list) is to use objects for that purpose. I often have source files that resemble: REBOL [...] compiler: make object! [ ;; just kidding!!! ;-) ... ;; lots of data definitions ... ;; lots of function definitions ... run: func [...] [ .... ] ] compiler/run ...blahblahblah... so that all of the innards are kept out of the collision zone. Another related trick is to have a *.r file create an object which you can keep up with as you wish (without creating other global words explicitly). A dinky example follows: First the file usemod.r 8<---------- REBOL [] toplevel: make object! [ thingie: do %submod.r run: func [n [integer!]] [ thingie/init 0 loop n [ prin thingie/next prin " -> " print thingie/curr ] loop n [ print thingie/prev ] ] ] toplevel/run 5 8<---------- ... then the file submod.r 8<---------- REBOL [] make object! [ _counter: 0 init: func [n [integer!]] [_counter: n] next: func [] [_counter: _counter + 1] curr: func [] [_counter] prev: func [] [_counter: _counter - 1] ] 8<---------- after which...
>> do %usemod.r
1 -> 1 2 -> 2 3 -> 3 4 -> 4 5 -> 5 4 3 2 1 0
>>
at the cost of only one global word (toplevel). HTH! -jn- Gregg Irwin wrote:
> Hi All, > > What is the recommended approach for avoiding naming clashes > in REBOL? I haven't gotten to the point of understanding > contexts and binding to know if this is the mechanism I would > need to use, or how best to organize a larger project with > multiple scripts that may have function name collisions. >
-- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com