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

[REBOL] Returning any value

From: lmecir:mbox:vol:cz at: 17-May-2002 17:42

Hi all, this is a repetition of Romano's and my findings with a couple of notes. If I want to define a Rebol function able to return any Rebol value, I can do it as follows: attempt-1: func [ value [any-type!] ] [ get/any 'value ] The ATTEMPT-1 function uses RETURN-less method of returning a value. This test reveals its weakness: type? attempt-1 make error! "" ** User Error: ** Near: type? attempt-1 make error! "" instead of getting the error! datatype as a result of the expression, the error is being fired. My second attempt tries to use RETURN to achieve the goal: attempt-2: func [ value [any-type!] ] [ return get/any 'value ] ATTEMPT-2 behaves better for errors, but it has another weakness: type? attempt-2 first [a:] ; == word! , while we want to get a SET-WORD! Here's another attempt: attempt-3: func [ value [any-type!] ] [ either error? get/any 'value [ return value ] [get/any 'value] ] This seems to work as it should (any testing appreciated). In my opinion all three attempts should be equivalent and both ATTEMPT-1 and ATTEMPT-2 show a Rebol design flaw. WARNING! Alhough I tried to write e.g. my %highfun.r to be as general as possible, It doesn't use the ATTEMPT-3 method! Therefore my %highfun.r is undoubtedly flawed at least until I rewrite it or RT change the interpreter behaviour (whatever happens first). Nevertheless, I hesitate to update it, because the ATTEMPT-3 surely isn't nice. Ciao L P.S. BTW, the last version of uses a changed version of the LOCALS? function (hope it doesn't cause any inconveniences) and it sports a repaired version of the LFUNC function with implicitly local set-words.