lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Wednesday, July 3, 2013, Roberto Ierusalimschy wrote:
> With my JSON library it is possible to write
>
>   getmetatable(db.null).__tojson = function () return "null" end
>
> and db.null would work for the JSON encoder as well.  And in the other
> direction you can just tell the decoder to use any arbitrary value for null.

It should be clear that how to represent "null" in JSON is a problem
quite different from how to represent "null" in Lua.

If we add a new value in Lua (call it null, empty, nothing, whatever)
to represent null in JSON, the problem with JSON is solved, because
we do not change JSON. This change is trivial to do, but only solves
the JSON problem.

If we add a new value in Lua (call it null, empty, nothing, whatever)
to represent null in *Lua*, the problem is not solved. Now Lua has a new
value, and therefore we need yet another value to represent this new
Lua value. Adding new values will not solve the problem in Lua. Period.

-- Roberto

Roberto,

Do you see a distinction between:

Calling a function to determine if a variable or table index has been defined

And

A new value

I do. `exists` could return true, false or even "upvalue" or "local" or some number which would represent the number of scopes up the stack it is from the current scope. 

No new value is required and Lua already has this answer, today, no?