# table

require "list" FIXME: allow require loops

sort: Make table.sort return its result
t: table
c: comparator function
returns
t: sorted table

subscript: Expose [] as a function
t: table
s: subscript
returns
v: t[s]

lookup: Do a late-bound table lookup
t: table to look up in
l: list of indices {l1 ... ln}
returns
u: t[l1]...[ln]

pathSubscript: Subscript a table with a string containing
dots
t: table
s: subscript of the form s1.s2. ... .sn
returns
v: t.s1.s2. ... .sn

empty: Say whether table is empty
t: table
returns
f: true if empty or false otherwise

size: Find the number of elements in a table
t: table
returns
n: number of elements in t

indices: Make the list of indices of a table
t: table
returns
u: list of indices

values: Make the list of values of a table
t: table
returns
u: list of values

invert: Invert a table
t: table {i=v ...}
returns
u: inverted table {v=i ...}

permute: Permute some indices of a table
p: table {oldindex=newindex ...}
t: table to permute
returns
u: permuted table

process: map a function over a table using an iterator
it: iterator
f: function
a: accumulator
i: index
v: value
returns
b: updated accumulator
a: initial value of the accumulator
t: table to iterate over
returns
a: final value of the accumulator

mapItem: map primitive for table.process
@f: function
returns
@g: function to pass to process to map a single item

filterItem: filter primitive for table.process
@f: predicate
returns
@g: function to pass to process to filter a single item

foldlItem: foldl primitive for table.process
@f: function
returns
@g: function to pass to process to foldl a single item

foldrItem: foldr primitive for table.process
@f: function
returns
@g: function to pass to process to foldr a single item

map: Map a function over a table
f: function
t: table
returns
m: result table {f (t[i1])...}

filter: Filter a table with a predicate
p: predicate
t: table
returns
m: result table containing elements e of t for which p (e)

clone: Make a shallow copy of a table, including any
metatable
t: table
returns
u: copy of table

deepclone: Make a deep copy of a table, including any
metatable
t: table
returns
u: copy of table

merge: Merge two tables
If there are duplicate fields, u's will be used. The metatable of
the returned table is that of t
t, u: tables
returns
r: the merged table

newDefault: Make a table with a default value
x: default value
[t]: initial table [{}]
returns
u: table for which u[i] is x if u[i] does not exist