lua-users home
lua-l archive

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


On Wed, Mar 14, 2018 at 7:24 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> The problems I am trying to solve are these:
>
> 1) A constructor like {x, y, z} should always create a sequence with
> three elements. A constructor like {...} should always get all arguments
> passed to a function. A constructor like {f(x)} should always get
> all results returned by the function. '#' should always work on these
> tables correctly.
>
> 2) A statement like 't[#t + 1] = x' should always add one more element
> at the end of a sequence.
>
> These are what confuse people all the time, these are what start new
> rounds of discussions around '#'.
>
> Once 'empty' and 'undef' are values, you break all those properties.
>
> I think we cannot use a value to represent the absence of a value, no
> matter how many no-value values we add. It is a contradiction. Several
> languages followed this path, always with bad results.
>
> -- Roberto

Ok, but, How Much Does it Cost? (sic)

New keyword. Two way to express the emptyness (one for functions, one
for tables, completly different).

And, honestly, the ones that are confused about the "Sequences with
holes" will be less confused about

```
local t = {1}
t[1] = undef
print('1', t[1] == undef)
print('2', t[1] == nil)
```

Why are both true? I know why, I am just anticipating the discussion
that will substitute the # ones. Then someone will ask "But, can we
just make case-2 to be false?". Than someone else will replace, "No
because It will mean to make undef a value" since

```
function first(a) return a[1] end
print('3', first(t) == nil)
```

case-3 should also be false.

And so on.