I'm providing a function that can read a hash table from disk and return it as a mutable data structure. This function works with Arc 3.1. (def make-mutable-cons (data)
(withs (ret nil)
(each el data
(push el ret))
ret))
(def make-mutable-table (data)
(withs (ret (table))
(maptable (fn (k v)
(if (is (type v) 'table)
(= (ret (sym k)) (make-mutable-table v))
(is (type v) 'cons)
(= (ret (sym k)) (make-mutable-cons v))
(= (ret (sym k)) v)))
data)
ret))
;; read a hash table from a file; but what you get back is mutable
(def riff-table (file)
(withs (immutable nil)
(= immutable (w/infile i file (read i)))
(make-mutable-table immutable)))
Here are some test data: arc> (= h (obj this "this" that 3 nested-hash-table (obj one "one" two "two" three 3) some-list (list 1 2 "three" 4)))
$ cat nested
#hash((nested-hash-table . #hash((three . 3) (one . "one") (two . "two"))) (some-list . (1 2 "three" 4 . nil)) (this . "this") (that . 3))
And here is an example how to use this function: arc> (= nt (riff-table "nested"))
#hash((nested-hash-table . #hash((three . 3) (one . "one") (two . "two"))) (some-list . (4 "three" 2 1 . nil)) (this . "this") (that . 3))
arc> (= (nt "this") "THIS")
"THIS"
arc> (= ((nt 'nested-hash-table) 'one) "ONE")
"ONE"
arc> (= (nt 'some-list) (list 5 6 "seven"))
(5 6 "seven")
arc> nt
#hash((nested-hash-table . #hash((three . 3) (one . "ONE") (two . "two"))) (some-list . (5 6 "seven" . nil)) (this . "this") (that . 3) ("this" . "THIS"))
|