all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Valentin Baciu <valentin@syntactic.org>
To: ishi soichi <soichi777@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: error "Odd number of elements in hashtable data
Date: Thu, 12 Jan 2012 10:55:30 +0200	[thread overview]
Message-ID: <CAKHQLnrOzakDS3=B61Q8QCs0yWD8zx5=h8eEaKevfKhauYvsgQ@mail.gmail.com> (raw)
In-Reply-To: <CAEjRLuT0U1EdbkDrjSwXkLMY+Py2daaFvD-D5_SrSPX02XomAg@mail.gmail.com>

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)))



      reply	other threads:[~2012-01-12  8:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-12  2:50 error "Odd number of elements in hashtable data ishi soichi
2012-01-12  8:55 ` Valentin Baciu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKHQLnrOzakDS3=B61Q8QCs0yWD8zx5=h8eEaKevfKhauYvsgQ@mail.gmail.com' \
    --to=valentin@syntactic.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=soichi777@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.