[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Unexpected error using tostring
- From: Sean Conner <sean@...>
- Date: Tue, 5 Mar 2019 00:56:38 -0500
It was thus said that the Great Magicks M once stated:
> function f() end
> tostring(f()) --what happens here?
> This code causes an error, which I think is not obvious, with the message "bad
> argument #1 to 'tostring' (value expected)" I believe this is because the
> number of values returned by f is 0 which means the vararg passed into
> tostring has length 0.
>
> This is quite odd in terms of how the code looks, now consider the
> following function:
> function transform(f)
> return function(x, ...) return f(x, ...) end
> end
> This looks rather redundant, but transform(tostring)(f()) will not produce
> an error, which is perhaps even weirder.
>
> Is this supposed to behave like this?
It could be related to this:
print(tostring())
print(tostring(nil))
-spc