[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Quest: real world "Lua array with holes" usage
- From: Tim Hill <drtimhill@...>
- Date: Sun, 24 Jul 2016 19:48:56 -0700
> On Jul 24, 2016, at 11:34 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>
> Of course any function can return nil among its returns, but maybe
> that might be considered a bad practice.
>
> My point is that, if nil is representing the absence of a value, it
> is weird not to have a third value but to have a fourth one. If nil
> is representing something else, probably it shouldn't be (as pointed
> out by others already).
>
> ("is weird" ~ "it might be considered weird”)
It’s weird *only* if the values are a strict list. If the values are (conceptually) a tuple, then of course an intermediate may be nil. While it could be argued that tuples should be returned as tables, you have the same problem; you can’t put a nil mid-way (and, as others have noted, returning a tuple directly can be faster and has less memory churn).
—Tim