[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hash-table-{to, from}-alist
From: |
Ted Zlatanov |
Subject: |
Re: hash-table-{to, from}-alist |
Date: |
Wed, 26 Nov 2008 10:06:13 -0600 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) |
On Wed, 26 Nov 2008 11:29:06 +0900 "Stephen J. Turnbull" <address@hidden>
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 <address@hidden> wrote:
>> #s<hash-table size 65 test 'eql weak 'key rehash-size 20.0 rehash-threshold
>> 0.001 data (1 2 5 env )>
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 <address@hidden>
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))
{
- Re: hash-table-{to, from}-alist, (continued)
- Re: hash-table-{to, from}-alist, Ted Zlatanov, 2008/11/24
- Re: hash-table-{to, from}-alist, Stephen J. Turnbull, 2008/11/24
- Re: hash-table-{to, from}-alist, Ted Zlatanov, 2008/11/25
- Re: hash-table-{to, from}-alist, Ted Zlatanov, 2008/11/25
- Re: hash-table-{to, from}-alist, Stefan Monnier, 2008/11/25
- Re: hash-table-{to, from}-alist, David De La Harpe Golden, 2008/11/25
- Re: hash-table-{to, from}-alist, Stefan Monnier, 2008/11/25
- Re: hash-table-{to, from}-alist, David De La Harpe Golden, 2008/11/26
- Re: hash-table-{to, from}-alist, Stephen J. Turnbull, 2008/11/25
- Re: hash-table-{to, from}-alist, David De La Harpe Golden, 2008/11/25
- Re: hash-table-{to, from}-alist,
Ted Zlatanov <=
- Re: hash-table-{to, from}-alist, Stefan Monnier, 2008/11/26
- Re: hash-table-{to, from}-alist, Ted Zlatanov, 2008/11/26
- Re: hash-table-{to, from}-alist, Ted Zlatanov, 2008/11/26
- Re: hash-table-{to, from}-alist, Stephen J. Turnbull, 2008/11/26
- Re: hash-table-{to, from}-alist, Davis Herring, 2008/11/26
- Re: hash-table-{to, from}-alist, Ted Zlatanov, 2008/11/26
- Re: hash-table-{to, from}-alist, Stefan Monnier, 2008/11/24
- Re: hash-table-{to, from}-alist, Stephen J. Turnbull, 2008/11/25
- Re: hash-table-{to, from}-alist, Miles Bader, 2008/11/22
- Re: hash-table-{to, from}-alist, tomas, 2008/11/22