all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* error "Odd number of elements in hashtable data
@ 2012-01-12  2:50 ishi soichi
  2012-01-12  8:55 ` Valentin Baciu
  0 siblings, 1 reply; 2+ messages in thread
From: ishi soichi @ 2012-01-12  2:50 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1073 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1858 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: error "Odd number of elements in hashtable data
  2012-01-12  2:50 error "Odd number of elements in hashtable data ishi soichi
@ 2012-01-12  8:55 ` Valentin Baciu
  0 siblings, 0 replies; 2+ messages in thread
From: Valentin Baciu @ 2012-01-12  8:55 UTC (permalink / raw)
  To: ishi soichi; +Cc: help-gnu-emacs

On Thu, Jan 12, 2012 at 4:50 AM, ishi soichi <soichi777@gmail.com> 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)))



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-12  8:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-12  2:50 error "Odd number of elements in hashtable data ishi soichi
2012-01-12  8:55 ` Valentin Baciu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.