-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtable.tem
40 lines (40 loc) · 2.65 KB
/
table.tem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(page "Table operations"
(newtable "Table operations"
(import "docs/table0.html")
(mac obj "[key value ...]" "Creates a table with the specified key/value
pairs. (The table can be considered an object with the keys as field names.)" (tests (obj key1 42 key2 "hello")))
(mac w/table "var [body ...]" "Assigns an empty table to var and then
executes body."
(tests (w/table t1 (= (t1 "a") 42) (write-table t1))))
(def tablist "table" "Returns the table as a list of key/value pairs"
(tests (tablist (obj key1 42 key2 "hello"))))
(def listtab "list" "Converts a list of key/value pairs to a table."
(tests (listtab '((key1 val1) (key2 val2)))))
(def read-table "[[input-port] eof]" "Reads a table (as a list of pairs) from the
given input-port or stdin. If end-of-file is encountered, the given eof value
is returned; if it is a list, it will be processed into a table." (tests (w/instring ins "((a 10)(b 20))" (read-table ins))))
(def load-table "filename [eof]" "Reads a table from the given filename. This
is similar to read-table, except the input is specified as a filename, rather
than an input-port."
(faketest (load-table "t") "#hash((a . 10) (b . 20))"))
(def safe-load-table "filename" "Loads a table from the given file, like
load-table. However, if an error is encountered, an empty table is returned
instead of an exception."
(faketest "(load-table \"tfile\")" "#hash((a . 10) (b . 20))"))
(def load-tables "filename" "Loads tables from the specified file until
end-of-file is reached. Returns a list of tables."
(faketest "(load-tables \"tfile2\")"
"(#hash((a . 10) (b . 20)) #hash(("foo" . 1) ("bar" . 2)))"))
(def write-table "h [output-port]" "Writes the table to the output-port (or
stdout) as a list of key/value pairs." (tests (write-table (obj a 1 b 2))))
(def save-table "table filename" "Writes the table to the specified filename
as a list of key/value pairs." (tests (save-table (obj a 10 b 20) "tfile")))
(op maptable "proc table " "Applies proc to each element of the table and returns the table."
(tests (maptable (fn (key val) (prn key " " val)) (obj a 1 b 2))))
(op table "" "Creates an empty hash table." (tests (table)))
(def destructive fill-table "table data" "Fills the table from the list <code>data</code>, which is interpreted as key-value pairs. <code>table</code> must already be a table." (tests (let tb (obj a 1 b 2) (fill-table tb '(c 3 d 4)))))
(def keys "table" "Returns a list of keys for the table." (tests (keys (obj a 1 b 2))))
(def vals "table" "Returns a list of values for the table." (tests (vals (obj a 1 b 2))))
(def memtable "keylist" "Creates a table with the value true for each key in <code>keylist</code>." (tests (memtable '(a b c))))
)
)