Should all functions return values?

Carl Sassenrath, CTO
REBOL Technologies
8-May-2006 23:27 GMT

Article #0024
Main page || Index || Prior Article [0023] || Next Article [0025] || 22 Comments || Send feedback

The suggestion has been made: should all functions return values? It is interesting to consider, and I am looking for your comments on this topic.

Actually, it turns out that all functions actually do return values internally in existing versions of REBOL. But, some functions return the unset value, which makes it appear as if the function returned no result.

The argument in favor of making all functions return arguments is primarily from usage cases such as:

if error? err: try [write %file data] [...]

The problem here is that write does not return a result, so err variable cannot be set, and most of the time an error will result.

** Script Error: err needs a value
** Near: error? err: try [write %file data]

A small number of other cases exist, such as when using print (which does not return a result).

It would be a simple matter to allow such functions to return a value, probably one of their arguments.

So, what do you think?


Updated 13-Jun-2024 - Edit - Copyright REBOL Technologies -