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 14:34

Hi again, two other variants of the CFUNC function: comment {var1} use [values pass-values in-new-context] [ pass-values: func [ {pass values to locals and do body} [throw] locals body ] [ set/any locals values do body ] in-new-context: func [ {do body with locals in new context} [throw] locals body ] [ values: make block! length? locals foreach word locals [ insert/only tail values get/any word ] use locals copy/deep reduce [ :pass-values locals body ] ] cfunc: function [ {make a closure} [catch] spec [block!] body [block!] ] [locals] [ locals: copy [] foreach item spec [ if all [any-word? :item not set-word? :item] [ append locals to word! :item ] ] throw-on-error [ func spec reduce [ :in-new-context locals body ] ] ] ] comment {var 2} use [in-new-context] [ in-new-context: function [ {do body with locals in new context} [throw] locals spec body ] [statement] [ statement: make block! 1 + length? locals append statement func spec body foreach word locals [ insert/only tail statement get/any word ] do statement ] cfunc: function [ {make a closure} [catch] spec [block!] body [block!] ] [locals spec2] [ locals: copy [] spec2: copy [[throw]] foreach item spec [ if all [any-word? :item not set-word? :item] [ append locals to word! :item append spec2 reduce [to lit-word! :item [any-type!]] ] ] throw-on-error [ func spec reduce [ :in-new-context locals spec2 body ] ] ] ]