From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Valentin Baciu Newsgroups: gmane.emacs.help Subject: Re: loading hash-table from a file? Date: Thu, 5 Jan 2012 10:35:18 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1325752531 29832 80.91.229.12 (5 Jan 2012 08:35:31 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 5 Jan 2012 08:35:31 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: ishi soichi Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 05 09:35:27 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RiinG-0003hx-6V for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jan 2012 09:35:26 +0100 Original-Received: from localhost ([::1]:33580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RiinF-0005Z2-Ja for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jan 2012 03:35:25 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:44553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RiinA-0005Yi-Kf for help-gnu-emacs@gnu.org; Thu, 05 Jan 2012 03:35:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Riin9-0007Q8-NB for help-gnu-emacs@gnu.org; Thu, 05 Jan 2012 03:35:20 -0500 Original-Received: from mail-vw0-f41.google.com ([209.85.212.41]:47914) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Riin9-0007Ph-EB for help-gnu-emacs@gnu.org; Thu, 05 Jan 2012 03:35:19 -0500 Original-Received: by vbbfn1 with SMTP id fn1so252347vbb.0 for ; Thu, 05 Jan 2012 00:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntactic.org; s=syntacticorg; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=V3DbwUkmSTzWPMP7o4lgONp6YpUgY5E3fx9BzVt+YJo=; b=kh2UVKQWweo4LUkpgSgisaiYHkXv5VJzL/xOqjI+7a77P8xi2arTrweCebWMvS4Cqx fE8gCn1JC7yTpdyMZuhWZp1poxiL5tf6Z21VHupXjPWWCzTkaP8/pkQ56D+50ARhqdQJ zcPNODuMM/1bXoZ3wB92oO/VnGrzGzlrP5VyA= Original-Received: by 10.52.28.238 with SMTP id e14mr419509vdh.96.1325752518477; Thu, 05 Jan 2012 00:35:18 -0800 (PST) Original-Received: by 10.52.171.76 with HTTP; Thu, 5 Jan 2012 00:35:18 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.212.41 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83345 Archived-At: On Thu, Jan 5, 2012 at 7:16 AM, ishi soichi wrote: > I have never used hash-table of Emacs Lisp but I believe it's useful as a > database. > > Say, I have a hundred key-value pairs, which are to be stored as > hash-table. > Can I save this as a (text?) file so that Emacs can load it when booting up? > > I am a little confused because if I use (cons key value), it outputs "(key . > value)" which can be written in a regular file. > If I wish to find the value from a key, all I need to do is to simply search > through the file. > > Do you think I can save the database using hash-table like this? > > soichi In my Emacs 24, I can read back a printed (simple) hash table. I am not sure weather using more complex data types as values will also work. ;; Writing the hash table to a "database" file (with-current-buffer (find-file-noselect "/tmp/x") (let ((h (make-hash-table))) (puthash 'a 0 h) (puthash 'b 1 h) (insert (format "%s" h)) (save-buffer))) ;; Reading back the hash-table object (type-of (read (find-file-noselect "/tmp/x"))) ;; hash-table