[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error "Odd number of elements in hashtable data

From: Valentin Baciu
Subject: Re: error "Odd number of elements in hashtable data
Date: Thu, 12 Jan 2012 10:55:30 +0200

On Thu, Jan 12, 2012 at 4:50 AM, ishi soichi <> wrote:
> I'm trying to develop a database using hash-table.
> As you can see, creating a file that contains the data of hash-table.
> (setq data-directory "~/(path)/hashtest")
> (with-current-buffer (find-file-noselect data-directory)
>   (let ((h (make-hash-table :test 'equal)))
>     (puthash "think" "hard" h)
>     (puthash "go" "this" h)
>     (puthash "come" "that" h)
>     (puthash "went" "gone" h)
>     (puthash "category" "bad" h)
>     (puthash "why" "how" h)
>     (puthash "what" "on" h)
>     (insert (format "%S" h))
>     (save-buffer)))
> in the "hashtest" file,
> #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data
> ("think" "hard" "go" "this" "come" "that" "went" "gone" "category" "bad"
> "why" "how" "what" "on" ...))
> But for checking,
> (with-current-buffer
>     (find-file-noselect data-directory)
>   (let ((ht (read (current-buffer))))
>     (gethash "go" ht)))
> gives an error,
> Debugger entered--Lisp error: (error "Odd number of elements in hashtable
> data")...
> "Odd number" does not make sense to me at all.
> Could anyone help me out?
> Thanks in advance!
> soichi

I get a different error: End of file during parsing. In my case it is
because the point remains at the end of the buffer after the hash
table has been serialized in the associated file.

In order to make it work I had to change the code which reads the hash
table to the following:

(with-current-buffer (find-file-noselect data-directory)
  (let ((ht (read (current-buffer))))
    (goto-char (point-min))                      ;; move the point to
the beginning of the buffer
    (gethash "go" ht)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]