lua-users home
lua-l archive

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

On Wed, Sep 14, 2016 at 7:04 AM, Roberto Ierusalimschy
<> wrote:
>> 3. As Josh Billings put it, "The trouble with people is not what
>> they don't know, but what they know and it ain't so." If your
>> sequence ain't a sequence, #t will give you a frontier, i.e.
>> a filled position where the next one is empty. So you can
>> just keep on doing "t[#t+1]=newvalue" and never overwrite
>> anything already in the array. This behaviour used to be
>> documented, was removed because it might confuse some
>> people, but now that it has become clear that people get
>> confused anyway, we hope that the next Lua release might
>> restore it, since the implementation has not changed.
> We are planning to restore it. The new explanation would go like this.
> (What sounds better, "border" or "frontier"?)
> --------------------------------------------------------------------------
> A *border* in a table 't' is any non-negative integer such that
>    (border == 0 or t[border] ~= nil) and t[border + 1] == nil
> That is, a border points to any position in a table where a non-nil value
> is followed by a nil value (or to 0, when position 1 is empty).
> For instance, the table {1, 2, 3, 4, 5} has only one border, 5.  The
> table {1, 2, 3, nil, 5} has two borders, 3 and 5.  The table {nil, 2, 3,
> nil, 5, nil} has three borders, 0, 3 and 5. The table {} has one border,
> 0.
> Note that any table has at least one border.
> Note also that keys that are not a non-negative integer
> do not interfere with the notion of borders.
> The table {x=1, y=10} has one border, 1. The table
> {[1.1] = 1, [-3] = 1, [0] = 1, 1, 2, 3} also has one border, 3.
> A table with exactly one border is called a *sequence*.
> The length operator #t returns a border for the table 't'.
> When t is a sequence, #t returns its only border, which corresponds to
> the intuitive notion of the length of the sequence.
> When t is not a sequence, #t can return any of its borders. (The exact
> one depends on details of the internal representation of the table.)
> --------------------------------------------------------------------------
> -- Roberto

I'm not sure I agree with the choice of "border." "Border" means that
some content is encapsulated on all sides, but this definition only
discusses one side. Think the \b pattern in PCRE for how I would
imagine something named "border" to behave.

"Frontier" feels more appropriate, but if we follow Dirk's suggestion
to avoid collision with %f then perhaps "edge" or "threshold" might be
a reasonable term.

/s/ Adam