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

[REBOL] Re: A hard question

From: lmecir:mbox:vol:cz at: 5-Feb-2001 21:54

Hi all, Frank solved my problem, and that is why I am able to generalize his solution and have: soft-func: function [ {Create a "soft return" function} spec [block!] body [block!] ] [modified-spec do-body thr-on fnc-return] [ modified-spec: head insert/only copy spec "Soft" use [thr fnc] [ thr-on: does [thr: on] fnc-return: func [[throw] fnc-result [any-type!]] [ either thr [ change/only third :fnc [throw] ] [ change/only third :fnc "Soft" ] return get/any 'fnc-result ] use [soft-return] [ soft-return: func [[throw] body-result [any-type!]] [ thr: off return get/any 'body-result ] do-body: bind/copy body 'soft-return ] fnc: func modified-spec reduce [ :thr-on :fnc-return :do-body ] do-body: does third second :fnc change skip second :fnc 2 :do-body :fnc ] ] with a help of SOFT-FUNC we are now able to write the HARD function or any other function with similar properties hard: soft-func [u v] [soft-return u first v] ; Error test: arg1: func [x] [return make error! x] arg2: ["some error"] probe disarm hard :arg1 arg2 make object! [ code: 800 type: 'user id: 'message arg1: "some error" arg2: none arg3: none near: [return make error! x] where: none ] arg1: func [[throw] x] [return x] arg2: [1] test: does [hard :arg1 arg2 2] test ; == 1 Regards Ladislav