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

[REBOL] Re: Functional programming in REBOL

From: lmecir:mbox:vol:cz at: 9-Aug-2001 18:52

Hi Larry et Rebols, another variant of CFUNC, which looks like the fastest from the most general versions. It uses the "fresh function creation" method to get a new context: cfunc: function [ {make a closure} [catch] spec [block!] body [block!] ] [locals in-new-context spec2 body2 i] [ locals: copy [] spec2: copy [[throw]] body2: reduce ['do 'func spec2 body] i: 1 repeat item spec [ if all [any-word? :item not set-word? :item] [ append locals to word! :item append spec2 reduce [to word! :item [any-type!]] append body2 reduce ['get/any 'pick 'locals i] i: i + 1 ] ] in-new-context: func [ [throw] locals ] body2 throw-on-error [ func spec reduce [:in-new-context locals] ] ]