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

[REBOL] Re: Refinements

From: jan:skibinski:sympatico:ca at: 12-Nov-2002 14:03

Hi Robert, I am sure there are many ways of approaching this task. Here is one: Provided are three functions: 'f1, 'f2 and refine. F2 is a worker, 'f1 is your caller and 'refine is a dispatching utility. Example:
>> f1 "Robert"
== "Robert is in the middle"
>> f1/left "Robert"
== "Robert is on the left"
>> f1/right "Robert"
== "Robert is on the right" Regards, Jan ------------------------------------------------------- f1: func [ x /left /right /local f ][ either left [ f: refine/left :f2 ][ either right [ f: refine/right :f2 ][ f: refine :f2 ] ] comment { Do what you need to do here and finally call your f2 with a preselected refinement} f x ] f2: func [ x /left /right ][ either left [ rejoin ["" x " is on the left"] ][ either right [ rejoin ["" x " is on the right"] ][ rejoin ["" x " is in the middle"] ] ] ] refine: func [ {Select a refinement /left /right or none for a function 'f} f [any-function!] /left /right /local result ][ pipe: func[fs][make function! [x] append copy fs 'x] either left [ result: pipe [f/left] ][ either right [ result: pipe [f/right] ][ result: pipe [f] ] ] :result ] Robert M. Muench wrote: