[cdr-discuss] notes on CDR 2 - generic hash table

I sent this to Ingvar back in the day; since there is now a public process I thought I'd send it again "for the record" Firstly, thanks for putting CDR 2 out there! (and thanks to powers behind the CDR process too). A few comments: 1. typo in last paragraph of section 0.2.1: "possibel" -> "possible" 2. Naming. I like longer names (they are easier to read and completion makes them easier to type). I'd rather: I also like consistency and hate abbreviations (I can never remember which abbreviation to use <smile>). So I'd suggest: hash-lookup hash-delete hash-empty! hash-map hash-count hash-size generic-hash-table-p I like lookup because reference (and ref) seem unclear to me whereas lookup is what we're doing. I like delete rather than remove because delete in Common Lisp signifies that the function is destructive. I like empty! rather than clear (or clr) because the meaning of empty if more obvious (to me). The ! further signifies that something drastic is happening. I like hash-map, hash-count and hash-size over map-generic-hash, generic-hash-table-count and generic-hash-table- size because they are more consistent with the naming of the other functions and because they are also shorter to type). FWIW, I'd rather that the hash-table argument went first in every function (I don't value consistency with the existing hash table implementation very highly). Lisp varies as to where is puts the "container" argument (nth versus elt versus aref... sigh) but here it is more likely that you are dispatching on the table and not the key and doing this would mean that every function had the table as it's second argument (I'd change hash-map too). (A big shout out to Chris Dean on this one!). HTH, and thanks again, -- Gary Warren King, metabang.com Cell: (413) 885 9127 Fax: (206) 338-4052 gwkkwg on Skype * garethsan on AIM

Gary King <gwking@metabang.com> writes:
2. Naming. I like longer names (they are easier to read and completion makes them easier to type).
Good suggestions. The Scheme SRFI documents have some nice names for hash table functions: http://srfi.schemers.org/srfi-69/srfi-69.html http://srfi.schemers.org/srfi-90/srfi-90.html
hash-lookup
I personally like REF or GET here, fwiw. As one data point in this discussion I'll describe what I do in my own code: I have a thin wrapper around the LispWorks hash table code that uses the names and behavior I want. I chose DICT so I wouldn't be confused by the CL functions. make-dict dict dict? dict-get dict-delete! dict-exists? dict-clear! dict-count map-dict for-each-dict dict->keys dict->values alist->dict dict->alist plist->dict dict->plist dict-emtpy? dict-best (There are a few functions missing in this list.) MAKE-DICT allows you to specify the test function and the hashing function as well as a flag for a weak hash. My default test and hashing functions are my own generic functions OBJECT-HASH and OBJECT-EQUAL? that try to do the "right thing" for a key of any type. The general case is obviously slower than a simple EQL hash table. I also use the Iterate package and have IN-DICT and COLLECT-DICT forms. One small point additional point. My map-dict will cons up the results in a list (it's more like mapcar than mapc) and the for-each-dict just iterates over the function and doesn't do any consing. Cheers, Chris Dean
participants (2)
-
Chris Dean
-
Gary King