lua-users home
lua-l archive

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


I will try to elaborate on what I meant in my previous statement. 

The concept I am referring to is the absence of a value, I'm not using concept to talk about something discussed in the manual or defined by lua necessarily. Just an abstract idea.

I did not intend the phrase "intangible second class value" to be read as hyperbole, perhaps I owe an explanation to my wording. 

Let's look at a very simple function declaration: 
function f(x) 
   return  x
end

If I call it f()  what is x? The answer is nil, but this is the same when we call f(nil). When we are just considering a pure lua function there is no way to know how f was called. There is no lua value to represent the difference. This to me satifies the definition "unable to be touched; not having physical presence." (intangible). Second class because we have to go through the process of using select with a vararg.

It is not good enough just to say that missing arguments are nil.
 
I do agree with you here, I was simply suggesting that removing this "missing", such that we couldn't use a roundabout method to check, would be more in line with lua's design as a whole.
I would be in favour of a value in lua to distinguish the two cases and not actually removing it though. Either way a proper mechanism or none at all is what I think is needed.

On Thu, 7 Mar 2019, 14:31 Dirk Laurie, <dirk.laurie@gmail.com> wrote:
Op Do. 7 Mrt. 2019 om 09:36 het Magicks M <m4gicks@gmail.com> geskryf:
>
> I'm not sure an intangible second class value to represent a concept is the lua way either.

The phrase "intangible second class value" deserves a compliment. It
misleads the reader by taking for granterd that 'none' is a concept,
represented by some kind of value.  Actually T_NONE is just a name for
an integer constant in C. There is no concept 'none', let alone a
value of whatever class to rpresent it. It might as well have been
called "missing" or "absent".

Read the manual carefully. Carefully. Every bit of it. In particular, this part:

~~~~
lua_type

[-0, +0, –]

int lua_type (lua_State *L, int index);

Returns the type of the value in the given valid index, or LUA_TNONE
for a non-valid (but acceptable) index. The types returned by lua_type
are coded by the following constants defined in lua.h: LUA_TNIL (0),
LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION,
LUA_TUSERDATA, LUA_TTHREAD, and LUA_TLIGHTUSERDATA.
~~~~

> The only reason it exists is due to the way the C API retreives arguments from the stack.

This statement is so vague that it is not even wrong.

T_NONE exists because Lua calls are allowed to provide any number of
arguments, and it is not a priori an error to provide fewer values
tnan the function woukl have been able to use.

It is not good enough just to say that missing arguments are nil. For
example, the library function table.insert, since
table.insert(tbl,key,nil) and table.insert(tbl,item) do different
things. You really need to know whether that third argument is
actually present.