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

[REBOL] Re: Refinements

From: joel:neely:fedex at: 13-Nov-2002 17:07

Hi, Robert, Just one more idea to throw into the discussion (I think! ;-) Robert M. Muench wrote:
> Hi, I have a bunch of functions that have the same two refinements: > > /left /right > > How can I propagate refinements from a function when calling an > other function? > > Example: > > my-func1: func [param /left /right][ > either left [side: ??][side: ??] > my-func2/side ?? > ] > > my-func2: func [param /left /right][ > ] >
I assume we want to avoid something like ... my-func2: func [param /left /right] [ either left [ either right [ my-func2/left/right twiddle param ][ my-func2/left twiddle param ] ][ either right [ my-func2/right twiddle param ][ my-func2 twiddle param ] ] ] my-func2: func [param /left /right] [ ;... ] ... for several reasons: 1) It's too easy to make a typo in all that "boilerplate"; 2) It's too hard to maintain; 3) It doesn't scale well (every added refinement doubles the amount of code required) 4) There's a time penalty for all of the "glue" that doesn't add useful computing. In addition, something like ... turn: func [n [integer!] /left /right /around][ if left [prin "turn left and then "] if right [prin "turn right and then "] if around [prin "turn around and then "] print ["walk" n "steps"] ] march: func [/left /right /around /local action activity][ action: copy [turn] activity: [10] if left [append action 'left] if right [append action 'right] if around [append action 'around] do head insert/only copy activity to-path action ] ... has the overhead of assembling the block to be DOne on every evaluation. That leads me to wonder about giving each refinement an explicit logical value, which can be passed on easily (with a bit of typing effort, to be sure) ... my-func2: func [ param /left leftparam [logic!] /right rightparam [logic!] ][ my-func2/left/right twiddle param leftparam rightparam ] my-func2: func [ param /left leftparam [logic!] /right rightparam [logic!] ][ ;... ] ... where LEFTPARAM and RIGHTPARAM take the place of the "flag-like" /LEFT and /RIGHT from before. Your thoughts? -jn- -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446