How Attached are we to Functions Return Last Result?

In JavaScript, the failure to specify a RETURN statement is basically the way of saying you don't return anything. Functions don't accidentally leak values, you just get undefined:

> function nada() { 1 + 2; }

> nada()
<- undefined

> function three() { return 1 + 2; }

> three()

I know this isn't how Rebol has historically operated. But the historical operation of Rebol can lead to the accidental leakage of a lot of values which the caller wasn't necessarily meant to see. There's currently a burden to annotate in the spec when a function doesn't return something (the <void>).

So in the "Let's not give JavaScript any upper hand" line of thinking, should this be re-evaluated? I must admit I kind of feel their way is clearer. :-/

1 Like

If return comes, make it optional. The current behaviour is fine by me. Adding return is undoing part of REBOL way, REBOL takes care of taking and returning the last result. If you like it or not. It is not the end-user but the programmer that has to deal with it and the programmer should be able to handle or use PHP or Java instead.
Having the function return without declaring variables or having to specify a RETURN statement is very useful in quicky programming.

This could also be another construct. MACRO perhaps, or INLINE...where the idea is to create something that substitutes an expression.

>> foo-macro: macro [x y] [append x y]
>> foo-macro [a b c] 'd
== [a b c d]

>> foo-function: function [x y] [append x y]
>> foo-function
; no result (e.g. void!)

Or something. I dunno, I think it's worth asking if it's a great idea to leak by default. I personally like the RETURN making it clear whether something is actually meant to be a return can be hard to tell when looking at:

foo: function [...] [

Is that intentionally returning the result of something-or-another? Or is that a function intended to have a side effect, whose result is not part of the contract?

1 Like


To me it is part of what defines Rebol. Every function which doesn't return anything disturbs the flow for me, and breaks the ability to chain functions together.
It is part of the programmers responsibility to return something sensible.
(Well, this is my opinion at least.)

1 Like