REBOL [ Title: "Conversions" Date: 23-Aug-2000 File: %conversions.r Author: "Brett Handley" Purpose: { Some datatype conversions } ] refine-function: function [ "Refines a function with the specified refinements." [catch] 'f "The function" refinements [any-block!] /refinements-only ][p][ p: to-path head insert/only head copy refinements f :p ] refine: function [ "Creates a refinement path." [catch] refinements [any-block!] "A block refinement names." ][p][ p: to-path head copy refinements :p ] unrefine: func [ "Opposite of refine" p [path!] ][ to-block :p ] apply-refined: func [ {Refine a function and apply it to its arguments} f [any-function!] refinements [block!] blkargs [block!] {Argument values} /local length statement result the-function ] [ the-function: to-refined-function f refinements statement: make block! (length: length? blkargs) * 3 + 3 insert statement [set/any 'result the-function ] repeat i length [ append statement [pick blkargs] append statement i ] do statement get/any 'result ] ; Example [ test-func: func[ /test-a /test-b ][ print "test-func" if test-a [ print "test-a" ] if test-b [ print "test-b" ] ] ; >> my-refined-function: refine-function test-func [test-a test-b] ; == test-func/test-a/test-b ; >> my-refined-function ; test-func ; test-a ; test-b ]