lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 27.07.2016 um 19:16 schröbte Nagaev Boris:
On Wed, Jul 27, 2016 at 7:18 PM, Daurnimator <quae@daurnimator.com> wrote:
On 27 July 2016 at 19:20, Martin <eden_martin_fuhrspam@gmx.de> wrote:

Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
print(1), print(2), print(3)
1
2
3
nil     nil

The 'nil, nil' output is the return value of that expression: print
doesn't return anything, but when you have a subsequent return value
the 'nothing' is coerced to `nil`.


Why does it print "nil, nil" and not "nil, nil, nil"?

As Daurnimator already indicated, no return value is a special case of multiple return values: In certain situations multiple (or no) values are coerced into one value, in other situations, like at the end of an expression list, they are taken as is. All `print()` calls return no value, but only the last call is the last expression of an expression list, so the other two calls are coerced to one `nil` value each.

Philipp