|
setmetatable(t, { __mode = 'strong' })
So, does "missing"/"undefined" singleton for handling holes in tables have a verdict? Seems quite compatible and easy to handle in old/new code.--2018-03-21 14:10 GMT-03:00 Hisham <h@hisham.hm>:On 21 March 2018 at 13:06, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> Many thanks for the examples. All of them actually would raise errors in
> my little experiment, but let us see them in the discussion about nils
> in tables.
I hope this shows how easy it is to find examples of the construct I
was talking about. :)
> In the examples from Hisham, I could not figure out whether we should see
> the nils as actual values or "instructions" to not add something.
> For instance, in the case of
>
> entity[k] = default_value(field)
>
> does a nil mean no default or a nil as the default? Would it make any
> difference to the program if the nil was added to the table?
In both cases it is an instruction to not add something. In
default_value(), because we have to interact with the outside world
(converting to and from JSON), when the default is "null" we return it
as ngx.null.
And I hope this shows how non-trivial it is to audit working codebases
regarding their usage of nil. :)
-- Hisham
"A arrogância é a arma dos fracos."
===========================
Me. Italo Moreira Campelo MaiaCo-fundador do Grupo de Usuários Python do CearáSecretário ForHacker (fb.com/ForHackerSpace)