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

Namespaces for functions

 [1/7] from: greggirwin::starband::net at: 28-Aug-2001 10:36


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. Thanks in advance, --Gregg

 [2/7] from: pwoodward:cncdsl at: 28-Aug-2001 12:50


Gregg - by default, the context of most names in REBOL is global. However, within the scope of a function, you can declare names to be local within it's context... For example: my-name: "Test" my-func: func [my-arg /local my-name] [ ;function body here... ] Essentially w/o the /local refinement, any reference to "my-name" within the function would affect the global value of my-name. I suspect that you could leverage a similar feature, along with paths in order to avoid namespace collisions. By loading a function library into a named value - my-image-lib: load %image-lib.r in theory I suppose you could then reference functions within the library something like: my-image-lib/function-x [arg1 arg2] Or something similar... - Porter Woodward

 [3/7] 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

 [4/7] from: greggirwin:starband at: 28-Aug-2001 11:49


Thanks Joel! Thanks Porter! That's exactly what I was after. --Gregg

 [5/7] from: tim::johnsons-web::com at: 28-Aug-2001 11:36

Re: Namespaces for functions/some tips


Hi Gregg: DISCLAIMER: I am not an advanced rebol programmer. If any "real" rebol find errors or omissions in the following, then it's to my benefit :>) Having said that: I'll share some of my approaches and caveats: 1)Build a block of system words NOTE: some will come from your user.r
>>all-rebol-words: first system/words
; now you have them in a block and you can print them, ; store them, whatever 2)Any time that you compose a word, check to see that it isn't a system word. I also highly recommend using the rebol function dictionary. 3)"Overloading": Let's say you're setting up an object with a method called "print". If you use 'print with the "print" method, the result will likely be a stack overflow resulting from recusion. You can "overload" this by using 'system/words/print. 4)Refinements: See above. And. If using refinements within an object. You can compose a block of the words in the object with something like this: Interpreter session follows:
>> do %cgilib.r ; load the object into memory >> cgi-words: first cgio ;build a block of object words
; now you've got a list of words that you can refer to by something like this: >> find cgi-words 'path-parts or just >> find first cgio 'path-parts Example: I've got object function member call 'hidden. In another function of the same object, I have a refinement called 'hidden. I use self/hidden to avoid the collision. OR I might want to chose a different strategy. We're getting a bit dicey here. 5)System words can be redefined like: sys-print: :print SCRIPT LIBRARY: http://www.rebol.org/script/index.html; System Object Browser http://www.reboltech.com/library/html/nonlocal.html HTH Tim On Tue, Aug 28, 2001 at 10:36:02AM -0600, Gregg Irwin wrote:
> Hi All, > What is the recommended approach for avoiding naming clashes in REBOL? I
<<quoted lines omitted: 7>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Tim Johnson <[tim--johnsons-web--com]> http://www.johnsons-web.com

 [6/7] from: greggirwin:starband at: 28-Aug-2001 14:57


Thanks Tim! Excellent information. I'm a big fan of IDEs and VB, for all the things they've screwed up (IMO), does have some really nice features in the IDE; A visual project outline, Intellisense, and the Object Browser being some big ones. I've always built tools for myself and I'm chomping at the bit to spend some time with REBOL so I can start building REBOL tools. First I have to get to the point where I really grok its basics subconsciously. Patience is a virtue.<g> Thanks again for your feedback. --Gregg

 [7/7] from: tim::johnsons-web::com at: 28-Aug-2001 15:01

Re: Namespaces for functions/some tips/IDEs


On Tue, Aug 28, 2001 at 02:57:52PM -0600, Gregg Irwin wrote:
> Thanks Tim! > Excellent information. I'm a big fan of IDEs and VB, for all the things
<<quoted lines omitted: 4>>
> to get to the point where I really grok its basics subconsciously. Patience > is a virtue.<g>
I've done work in VBA and was impressed by some of the built-in features. Myself, I've moved away from IDE in any languages that I work in. However, I agree that a good IDE for rebol would be an attractive feature. One of the negative things about IDEs that I have encountered is that they frequently don't allow one to "plug in" their favorite editor. Given that there could be a major learining curve in picking up rebol, it would be an enhancement offer the user of that IDE the freedom of selecting an editor. MHO : Tim
> Thanks again for your feedback. > > --Gregg > > -- > To unsubscribe from this list, please send an email to > [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Tim Johnson <[tim--johnsons-web--com]> http://www.johnsons-web.com

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted