[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Possible misleading error message in Lua?
- From: "Joseph C. Sible" <josephcsible@...>
- Date: Sat, 22 Oct 2022 13:55:49 -0400
https://stackoverflow.com/q/62030588/7509065 is a very similar
question. The essence of what you wrote is this:
(foo)(bar)
(baz)(qux)
And the ambiguity was whether you meant (foo)(bar); (baz)(qux) or
(foo)(bar)(baz)(qux). In Lua 5.1 in older, such ambiguity resulted in
the error you mentioned. In newer versions, it assumes that you mean
the latter. Since your (foo)(bar) ends up eventually returning nil,
you get an error when you try to call its result as if it were another
function.
On Sat, Oct 22, 2022 at 4:26 AM Sean Conner <sean@conman.org> wrote:
>
>
> For reasons, I have the following Lua code in a file:
>
> (function(s)
> if #s > 0 then
> print(s)
> return debug.getinfo(1,'f').func(s:sub(1,math.floor(#s / 2)))
> end
> end)(string.rep("-",64))
>
> ;
>
> ((function(f)
> local function g(...) return f(g,...) end
> return g
> end)(function(f,s)
> if #s > 0 then
> print(s)
> return f(s:sub(1,math.floor(#s / 2)))
> end
> end))(string.rep("+",64))
>
> These are two different ways of an anonymous function calling itself
> recursively (the first is using the hack of calling debug.getinfo(), and the
> second is using the Y-combinator). When the code is run, using Lua 5.1 or
> higher, the output is:
>
> ----------------------------------------------------------------
> --------------------------------
> ----------------
> --------
> ----
> --
> -
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ++++++++++++++++++++++++++++++++
> ++++++++++++++++
> ++++++++
> ++++
> ++
> +
>
> Yet comment out that lone semicolon, and the results are very different.
> In Lua 5.1:
>
> lua-51: b.lua:12: ambiguous syntax (function call x new statement) near '('
>
> But for versions of Lua 5.2 or higher:
>
> ----------------------------------------------------------------
> --------------------------------
> ----------------
> --------
> ----
> --
> -
> function: 0x8aef2f8
> lua-54: b.lua:2: attempt to call a nil value
> stack traceback:
> b.lua:2: in main chunk
> [C]: in ?
>
> I was wondering what the issue was until I went back to Lua 5.1 and it
> reported back an actionable error message (in my humble opinion) that
> cleared the issue right up. I'm just curious as to why the change? Was it
> harder to detect in Lua 5.2+?
>
> -spc