[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Syntax/implementation question
- From: Daurnimator <quae@...>
- Date: Wed, 27 Jul 2016 09:18:13 -0700
On 27 July 2016 at 19:20, Martin <eden_martin_fuhrspam@gmx.de> wrote:
> Hi all,
>
> I'm experimenting with lua syntax and cannot understand why in
> interpreter I'm getting such output
>
> Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
>> print(1), print(2), print(3)
> 1
> 2
> 3
> nil nil
>
> When running this code from standalone file output is
>
> $ lua test_something.lua
> lua: test_something.lua:1: syntax error near ','
>
> which is what I awaiting.
>
> Any hints?
>
The 5.3 REPL attempts to prefix code with `return `
i.e. you are running:
`return print(1), print(2), print(3)`
The argument evaluation order is undefined (so you're lucky you see
1,2,3 in order).
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`.