;; Naive but "magical" on-disk persistence.
;; Just a demo, don't use this code for real.
(= ptables* ())
(def ptable (fname)
(let tbl (safe-load-table fname)
(push (list tbl fname) ptables*)
tbl))
(let _sref sref
(def sref (com val ind)
(let fnam (and (isa com 'table) (alref ptables* com))
(do1 (_sref com val ind)
(when fnam (save-table com fnam)))))
)
I initially thought 'disktable works like this, but 'disktable is actually just small sugar around 'save/load-table to save you some keystrokes. You still have to explicitely save the file to the disk by calling 'todisk, and this is the kind of things I easily forget to do.'ptable is more like what Elephant (http://common-lisp.net/project/elephant/) offers you: nearly completely transparent on-disk persistence. arc> (= users* (ptable "usrs.db"))
#hash()
arc> (= (users* "admin") "adminpwd"
(users* "palsecam") "12345")
12345
arc> (quit)
... later ...
arc> (= users* (ptable "usrs.db"))
#hash(("admin" . "adminpwd") ("palsecam" . "12345"))
arc> (wipe (users* "admin"))
nil
arc> (time:for i 0 1000 (= users*.i i))
time: 1490 msec. ; the file is rewritten at every pass of the loop...
nil
$ cat usrs.db # in your shell
(("palsecam" "12345") (1000 1000) (999 999)
[...]
(6 6) (5 5) (4 4) (3 3) (2 2) (1 1) (0 0))
I don't know if 'sref is the right place to make this modification. A big trade-off is that all calls to 'assign (and so to '=, 'set, etc.) are slower.Need a 'smart-save-table that would somehow delay the writing to the disk. And a SSD :-). |