[plt-scheme] Reading/writing hash-tables

From: Noel Welsh (noelwelsh at gmail.com)
Date: Wed Oct 31 05:04:32 EDT 2007

Cookbook works for me:

  http://schemecookbook.org/Cookbook/HashReadAndWrite

I tried with lists as values and it seems to work ok:

> (define port (open-output-string))
> (write-hash-table
    (make-immutable-hash-table '((a . (1 2)) (b . 3)))
    port)
> (get-output-string port)
"#hasheq((a . (1 2)) (b . 3))"
> (read-hash-table (open-input-string (get-output-string port)))
#<hash-table>

N.

On Oct 31, 2007 12:10 AM, David Van Horn <dvanhorn at cs.brandeis.edu> wrote:
> If I write a hash table, like this:
>
>     (write #hash((f . (10))))
>
> Then #hash((f 10)) is written on the current port, but I can't read this
> back in since the reader complains:
>
>     read: expected `.' and value for hash
>
> Is this intended?  Can either the reader or writer be changed so I can
> read and write hash tables?
>
> Thanks,
> David


Posted on the users mailing list.