[REBOL] Re: Namespaces for functions
From: joel:neely:fedex at: 28-Aug-2001 11:59
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:
compiler: make object! [ ;; just kidding!!! ;-)
;; lots of data definitions
;; lots of function definitions
run: func [...] [
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
toplevel: make object! [
thingie: do %submod.r
run: func [n [integer!]] [
loop n [
prin " -> "
loop n [
... then the file submod.r
make object! [
init: func [n [integer!]] [_counter: n]
next: func  [_counter: _counter + 1]
curr: func  [_counter]
prev: func  [_counter: _counter - 1]
>> do %usemod.r
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
at the cost of only one global word (toplevel).
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