[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suggestion: Lua 5.3 -- Named Return Values
- From: Coda Highland <chighland@...>
- Date: Wed, 20 Nov 2013 09:04:02 -0800
On Wed, Nov 20, 2013 at 3:26 AM, Sir Pogsalot <sir.pogsalot@gmail.com> wrote:
> I think this sort of thing has an official name... in Ruby the last
> statement -- what it evaluates to -- gets returned if it isn't explicitly
> preceded with a 'return '. In Lua you cannot have expressions in the middle
> of nowhere. You can have s2 = a * b, but you can't have a * b. It might
> look a tad confusing to have s2 = a * b and expect that value to be returned
> if you're reviewing the code...
Just for historical background: Pascal and BASIC use this behavior
exclusively. In these languages, the way that you return a value from
a function is to assign the value to the name of the function. There's
no "return" statement at all. (Modern BASIC exposes "Exit Function" as
a way to return from the function without running off the end of it,
but you still have to exclusively assign the return value before you
get that far. Pascal might offer a similar feature but I haven't used
it in 20 years.)
/s/ Adam