REBOL3 tracker
  0.9.12 beta
Ticket #0002241 User: anonymous

Project:

Previous Next
Short URL: http://issue.cc/r3/2241
rss
TypeWish Statusdismissed Date8-Aug-2015 22:08
Versionr3 master CategoryEvaluation Submitted byfork
PlatformAll Severitymajor Prioritynormal

Summary zero-arity RETURN, give UNSET! by default, /WITH to give back a value
Description With it not feasible/desirable to make a special 'definitionally-scoped' EXIT to go along with the RETURN: word on each function, the question came of how to pass an UNSET! to return to get equivalent functionality. This was addressed in #2200, and questions of whether 'return ()' was literate, or if a special VOID function should be created to conveniently make UNSETs.

While 'not the way it has been in the past', the idea of a zero-arity RETURN has legs.

(1) Idiomatically in Rebol, you don't generally need a RETURN to give back a value from a function, since that they evaluate to the last value in the body block. Some people (including myself, actually) have resisted this as not clearly documenting that the function returns something...and put a RETURN on the last line anyway (C-family language habits die hard). The argument for not doing so is that the return "costs extra" for zero difference in behavior, and one can make a reasoned case that a zero-arity-defaulting return would be *better* for putting at the end of functions to document that they return nothing. That would actually have a suppressive effect of giving back an UNSET! instead of leaving whatever the last evaluation was.

(2) When the idea originally came up (with @rgchris, who was thinking a zero-arity RETURN might give back NONE), there wasn't a good candidate for the value-returning. RETURN/RETURN was terrible of course, and RETURN/VALUE would look bad if it was RETURN/VALUE VALUE. The suggestion of switching BREAK to BREAK/WITH offered a short name that could be applied consistently, and RETURN/WITH VALUE is short and literate.

(3) Having unification of BREAK/WITH, RETURN/WITH, QUIT/WITH, and upcoming with a new proposed meaning for EXIT as EXIT/WITH groups these operations into a class where their behavior makes sense.

(4) Consequence-wise, if a function is expected to return a value and gives back an UNSET! because you said RETURN VALUE instead of RETURN/WITH VALUE, this is an error likely to be caught when FOO: MY-FUNC X Y Z is run. The missing refinement will be easily found, and pinpointed at the location where the problem is. This makes it more learnable.

With definitionally-scoped return, this can't be wedged into a "compatibility-mode" under the current concept...because RETURN would not be an ordinary word. This may suggest thinking harder about how to make it possible to get MAKE FUNCTION! to be able to use a different word besides RETURN for its definitionally-scoped operator, and perhaps a similar treatment is needed for SELF to make Rebol live up to the "no keywords" vision.

But in summary, with an encouragement of new programmers to not think of needing to put RETURN RESULT at the end of functions, the total number of usages of RETURN would go down somewhat. In those reduced cases, some percentage of them would be all right not taking a value...and some percentage of them would want to return a value. The similarity to BREAK and BREAK/WITH would be a learnable advantage.
Example code

			

Assigned ton/a Fixed in- Last Update3-Jan-2016 21:31


Comments
(0004674)
Ladislav
3-Jan-2016 21:31

We already do have a corresponding zero-arity function. It is called EXIT.

Date User Field Action Change
3-Jan-2016 21:31 ladislav Status Modified submitted => dismissed
3-Jan-2016 21:31 ladislav Comment : 0004674 Added -
8-Aug-2015 22:18 Fork Description Modified -
8-Aug-2015 22:14 Fork Description Modified -
8-Aug-2015 22:08 Fork Ticket Added -