Re: no return value vs. nil return value(s)
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: no return value vs. nil return value(s)
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: 2011年9月11日 20:52:27 +0200
On 11/09/2011 20.20, Eduardo Ochs wrote:
[...]
Does the code below help?
fall = function () end
ret = function () return end
retnil = function () return nil end
this = function (...) return ... end
print() --> (nothing)
print(nil) --> nil
print(nil, nil) --> nil nil
print(fall()) --> (nothing)
print(ret()) --> (nothing)
print(retnil()) --> nil
print(this()) --> (nothing)
print(this(nil)) --> nil
print(this(nil, nil)) --> nil nil
print(select("#")) --> 0
print(select("#", nil)) --> 1
print(select("#", nil, nil)) --> 2
print(select("#", fall())) --> 0
print(select("#", ret())) --> 0
print(select("#", retnil())) --> 1
print(select("#", this())) --> 0
print(select("#", this(nil))) --> 1
print(select("#", this(nil, nil))) --> 2
The language would be more complex and less elegant if "return" and
"return nil" were the same - it wouldn't be so easy to return an empty
list of results...
Thank you for the reply.
Your code samples were very clear, but I'm not arguing neither about the
usefulness/coherence of the current semantics nor about changing it.
I wanted to make use of the current semantic difference between "return"
and "return nil", but then I realized that I could be using a not well
defined "feature".
Cheers,
Eduardo Ochs
eduardoochs@gmail.com <mailto:eduardoochs@gmail.com>
http://angg.twu.net/
To Dirk:
On 11/09/2011 20.15, Dirk Laurie wrote:
On Sun, Sep 11, 2011 at 04:47:34PM +0200, Lorenzo Donati wrote:
But it is not clear that "return" with an empty explist is the same as
returning with no return statement (currently it behaves that way, but
can we rely on that?)
Racking my brains and letting my imagination roam, I have come up with
a complete inventory of what besides an empty explist might be returned
if no return statement is encountered. It is given below between the
two comment lines.
-- start inventory
-- stop inventory
Sorry, but that's not the point. As I said above I'm not saying it's
something strange. It is very intuitive, but it is undefined, as far as
I can see.
I just wanted to know if it is intentionally left undefined or it is
something we can rely on.
There are other areas in Lua where being intuitive doesn't mean
guaranteed (because of the trade-offs Lua team had to do), so my
question is not so bizarre IMHO.
Dirk
Cheers
-- Lorenzo