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: Wed, 26 Nov 2008 10:06:13 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <86prkiiia2.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> <87k5ari5jh.fsf@xemacs.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1227715844 13126 80.91.229.12 (26 Nov 2008 16:10:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Nov 2008 16:10:44 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 26 17:11:47 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 1L5MzP-0006Hd-SD for ged-emacs-devel@m.gmane.org; Wed, 26 Nov 2008 17:11:44 +0100 Original-Received: from localhost ([127.0.0.1]:49415 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5MyF-0000IF-UB for ged-emacs-devel@m.gmane.org; Wed, 26 Nov 2008 11:10:32 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L5MvZ-0005lE-Nw for emacs-devel@gnu.org; Wed, 26 Nov 2008 11:07:45 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L5MvJ-0005bg-Lk for emacs-devel@gnu.org; Wed, 26 Nov 2008 11:07:32 -0500 Original-Received: from [199.232.76.173] (port=52109 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5MvI-0005b7-Mr for emacs-devel@gnu.org; Wed, 26 Nov 2008 11:07:28 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:45624 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 1L5MvE-0005m3-Lg for emacs-devel@gnu.org; Wed, 26 Nov 2008 11:07:26 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L5Mv8-0004rS-Cr for emacs-devel@gnu.org; Wed, 26 Nov 2008 16:07:18 +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 ; Wed, 26 Nov 2008 16:07:18 +0000 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 26 Nov 2008 16:07:18 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 134 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:s9igTBUrb3nXaC35JL9GosB/RBM= 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:106199 Archived-At: On Wed, 26 Nov 2008 11:29:06 +0900 "Stephen J. Turnbull" wrote: SJT> Ted Zlatanov writes: >> OK, I'll make :test optional. Is size mandatory? I ask since you put >> it in your example, but you could have done so to illustrate >> parameters. SJT> It's not mandatory in the read syntax, but an accurate estimate will SJT> avoid some consing at read time. As an implementation detail, the SJT> write syntax does include it if non-zero. Since it doesn't matter, I'll leave it in even if zero. I think it improves legibility at the cost of 7 bytes. SJT> Good. I would be very annoyed if we had to support an alternative SJT> syntax. Right, my goal here is to find the simplest solution that works for everyone. I changed it to #s(hash-table ...) as discussed. On Tue, 25 Nov 2008 20:46:23 -0500 Stefan Monnier wrote: >> #s SM> Looks OK, except I don't think it's a good idea to include ' in front of SM> key and eql. I know it's what we do right now, but in order to read it SM> back in, it's going to be more trouble. Also I'd generally prefer using SM> ":weakness" rather than "weak", so it's as close as possible to the key SM> args passed to make-hash-table. OK, both done. >> I know it's broken for circular references (e.g. (puthash 6 h h) >> above). How should I handle that? SM> The same way as the other circularities. I.e. it should mostly SM> "just work", except you'll have to change the code that does the SM> first pass so that it doesn't skip hash tables. Sorry, I don't know what you mean. My iterator doesn't skip hash tables, does it? Or are you discussing something else? SM> Shouldn't it be !NILP (h->test) rather than SYMBOLP (h->test)? SM> Here as well [weakness], !NILP should be sufficient. SM> And again [rehash_size and rehash_threshold] !NILP sounds preferable. All done. On Wed, 26 Nov 2008 05:46:32 +0000 David De La Harpe Golden wrote: DDLHG> N.B. It's actually #s(...) in XEmacs too, at least when variable DDLHG> print-readably is t. Otherwise the not-readable #<...> (no "s") is DDLHG> used, as per Stephen J. Turnbull's posts to this thread, also shown in DDLHG> [1] I am still printing the two versions of the object in the attached patch, but I can of course make it conditional on print-readably. IMHO hashtables should always be printed completely and should be treated like lists and vectors. If, however, compatibility with XEmacs is desired or people feel strongly for print-readably, I will implement with print-readably. It prints an extra space at the end, which I still have as a simple TODO. I also have to handle circular references, but otherwise it seems pretty reasonable. 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 26 Nov 2008 16:01:57 -0000 *************** *** 2052,2057 **** --- 2052,2107 ---- sprintf (buf, " 0x%lx", (unsigned long) h); strout (buf, -1, -1, printcharfun, 0); PRINTCHAR ('>'); + + /* + implement a readable output, e.g.: + #s(hash-table size 2 test equal data (k1 v1 k2 v2)) + */ + /* always print the size */ + sprintf (buf, "\n\n\t#s(hash-table size %ld", (long) XVECTOR (h->next)->size); + strout (buf, -1, -1, printcharfun, 0); + + if (!NILP(h->test)) + { + strout (" test ", -1, -1, printcharfun, 0); + print_object (h->test, printcharfun, 0); + } + + if (!NILP(h->weak)) + { + strout (" weakness ", -1, -1, printcharfun, 0); + print_object (h->weak, printcharfun, 0); + } + + if (!NILP(h->rehash_size)) + { + strout (" rehash-size ", -1, -1, printcharfun, 0); + print_object (h->rehash_size, printcharfun, 0); + } + + if (!NILP(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)) {