Constructs a table.
The global tab
is bound both to a function and to a macro.
Each argument to the tab
function must be an array of length two, (key value)
. The
function constructs a new table, and assigns each key/value pair to it in turn, as though
calling (= [the-tab key] value)
.
The tab
macro is similar, but it receives its key/value pairs as special syntax,
rather than requiring them to be allocated as individual arrays. When it encounters a
splayed argument, ..base
, then base
must evaluate to an iterator which produces
key/value pairs; they are all inserted into the table as it's being constructed, as though
calling (extend! the-tab ..base)
.
Duplicate keys are permitted.
(let orig #((a 0) (b 1)))
(print (tab ('c 2))) ; prints #((c 2))
(print (tab ('c 2) ('c 3))) ; prints #((c 3))
(print (tab ..orig ('a 10))) ; prints #((b 1) (a 10) (c 2))
; bind the local `ftab` to the global `tab` function
(let ftab tab)
(print (ftab ..orig)) ; prints #((b 1) (a 0))
(print (ftab (arr 'a 0))) ; prints #((a 0))