From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.devel Subject: Re: hash-table-{to, from}-alist Date: Tue, 25 Nov 2008 17:50:45 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <86d4gjnz56.fsf@lifelogs.com> References: <863aknitfg.fsf@lifelogs.com> <20080830051807.GB9625@tomas> <86bpwe9su5.fsf@lifelogs.com> <867i6z1jo5.fsf_-_@lifelogs.com> <86ej14vhvg.fsf@lifelogs.com> <20081122054510.GA28298@tomas> <873ahkkkt5.fsf@xemacs.org> <20081122152126.GA4142@tomas> <87vdufk6do.fsf@xemacs.org> <867i6tt4yz.fsf@lifelogs.com> <87bpw4k1z6.fsf@xemacs.org> <86bpw3d829.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1227657132 11372 80.91.229.12 (25 Nov 2008 23:52:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Nov 2008 23:52:12 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 26 00:53:15 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L57iT-0005j2-PH for ged-emacs-devel@m.gmane.org; Wed, 26 Nov 2008 00:53:14 +0100 Original-Received: from localhost ([127.0.0.1]:57496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L57hK-0007ir-Bu for ged-emacs-devel@m.gmane.org; Tue, 25 Nov 2008 18:52:02 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L57hF-0007iW-L4 for emacs-devel@gnu.org; Tue, 25 Nov 2008 18:51:57 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L57hD-0007i8-Ew for emacs-devel@gnu.org; Tue, 25 Nov 2008 18:51:56 -0500 Original-Received: from [199.232.76.173] (port=55245 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L57hD-0007i2-77 for emacs-devel@gnu.org; Tue, 25 Nov 2008 18:51:55 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:47684 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L57hC-0001jN-M8 for emacs-devel@gnu.org; Tue, 25 Nov 2008 18:51:54 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L57h8-0005Xv-GZ for emacs-devel@gnu.org; Tue, 25 Nov 2008 23:51:50 +0000 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 25 Nov 2008 23:51:50 +0000 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 25 Nov 2008 23:51:50 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 95 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:XN/ttF5D+7esiU7rNLxstEw8PBA= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:106174 Archived-At: Here's a patch to print.c to implement printing out a hashtable's properties and content as discussed. I *think* I'm doing it right based on what I see elsewhere in print.c and fns.c. I rely on print_object to do the work. I know the indentation is off, sorry. This patch does: (let ((h (make-hash-table :rehash-size 20.0 :rehash-threshold 0.001 :weakness 'key))) (puthash 1 2 h) (puthash 5 'env h) (print h)) --> # #s I know it's broken for circular references (e.g. (puthash 6 h h) above). How should I handle that? The new output is offset and printed after the old-style output as a sanity check. Let me know if the code is OK and I'll make it the only output of printing a hashtable, clean it up (based on any comments I get and the TODO items), and go on to writing the read code. I won't commit it of course, just keep it as a patch until the trunk is open again. Thanks Ted Index: print.c =================================================================== RCS file: /sources/emacs/emacs/src/print.c,v retrieving revision 1.253 diff -c -r1.253 print.c *** print.c 31 Jul 2008 05:33:53 -0000 1.253 --- print.c 25 Nov 2008 23:40:54 -0000 *************** *** 2052,2057 **** --- 2052,2108 ---- sprintf (buf, " 0x%lx", (unsigned long) h); strout (buf, -1, -1, printcharfun, 0); PRINTCHAR ('>'); + + /* + implement a readable output: + #s(hash-table size 2 test equal data (k1 v1 k2 v2)) + */ + /* always print the size */ + sprintf (buf, "\n\n\t#snext)->size); + strout (buf, -1, -1, printcharfun, 0); + + if (SYMBOLP (h->test)) + { + strout (" test '", -1, -1, printcharfun, 0); + print_object (h->test, printcharfun, 0); + } + + if (SYMBOLP (h->weak) && ! NILP(h->weak)) + { + strout (" weak '", -1, -1, printcharfun, 0); + print_object (h->weak, printcharfun, 0); + } + + if (FLOATP (h->rehash_size) || INTEGERP (h->rehash_size)) + { + strout (" rehash-size ", -1, -1, printcharfun, 0); + print_object (h->rehash_size, printcharfun, 0); + } + + /* the rehash threshold must be 0 < threshold < 1 so it's never an integer */ + if (FLOATP (h->rehash_threshold)) + { + strout (" rehash-threshold ", -1, -1, printcharfun, 0); + print_object (h->rehash_threshold, printcharfun, 0); + } + + strout (" data ", -1, -1, printcharfun, 0); + + /* print the data here as a plist */ + int i; + + PRINTCHAR ('('); + for (i = 0; i < HASH_TABLE_SIZE (h); ++i) + if (!NILP (HASH_HASH (h, i))) + { + print_object (HASH_KEY (h, i), printcharfun, 0); + PRINTCHAR (' '); + print_object (HASH_VALUE (h, i), printcharfun, 0); + PRINTCHAR (' '); /* TODO: should not be printed at end */ + } + PRINTCHAR (')'); + PRINTCHAR ('>'); + } else if (BUFFERP (obj)) {