lua-users home
lua-l archive

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


On Wed, Mar 14, 2018 at 16:40 pocomane <pocomane_7a@pocomane.com> wrote:
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.

I’m struggling with why there seems to be so much of a struggle with this. 

Making tables return something other than nil for a default value on missing keys would break everything and solve nothing. 

It looks like an elegant solution to a problem that has been argued about ad nauseum since forever. It may not be _the_ syntax (or name) that everyone would choose and that would be true for absolutely every solution that could be imagined. And it has a lot going for it.

The best way to critique the idea is to try it with real code, not argue about it in theory. I did that before with the “no string to number coercion” flag and I learned a lot.  


-Andrew