[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [PATCH] Add new function to test whether a key is present in a hash
RE: [PATCH] Add new function to test whether a key is present in a hash table.
Mon, 19 Feb 2018 09:26:37 -0800 (PST)
> DA> 2. The function name should have `key' in it, I think. Suggestion:
> DA> `hash-table-contains-key-p' or even just `hash-table-key-p'.
> It seems a bit strange that the name isn't something like "hashash",
> since knowing "puthash" and "gethash" would never help you guess
Right. And knowing `hash-table-contains-key-p' wouldn't
help you guess `puthash' or `get-hash'.
But that's the fault of `puthash' and `gethash'. ;-)
It's `puthash' and `gethash' that are not so conventional
for Emacs. They are borrowed from Common Lisp. Likewise,
`maphash', `remhash', and `clrhash'. Those names predate
Common Lisp even.
`puthash', `gethash', `remhash', etc. could be made
aliases of, say, `hash-table-put', `hash-table-get',
`hash-table-remove', etc. (I'm not saying they should.)
`puthash' seems to be the only Emacs `put*' function
whose name doesn't start with `put-' (apart from `put'
itself). Same thing for `gethash' (except that there
are also `getenv' and `getf'). The Emacs convention is
to use prefix `put-' or `get-'.
Another (more common?) convention in Emacs is to put the
object type first: `string-match', `bool-vector-union',
`mode-line-next-buffer', `menu-bar-open', `marker-buffer',
`buffer-size', `window-child', `frame-edges', etc.,
especially for functions that extract parts of an object.
Yet another convention is to put the verb first,
especially for "utility" verbs: `map-*', `make-*',
`put-*', `get-*', `copy-*', `delete-*', etc.
Finally, a library prefix is often used: `ad-get-*',
`ange-ftp-get-*', `bookmark-get-*', `comint-get-*',
`dired-get-*', `ediff-get-*', `gnus-get-*' ...
These are the functions I see with "hash" in their names:
0. Those that (I guess) have nothing to do with hash tables:
I mention these to point out that names like `puthash'
don't really, on their own, make clear that they have
to do with a hash table.
1. Those that are about hash-table hashing but (I guess)
don't have a hash table as the main object:
2. Those (non-CL) that have a hash table as the main object:
3. Common-Lisp emulation functions for hash tables:
Note that except for those names inherited from older
Lisps, Common Lisp spells out `hash-table' in the
The most common convention, so far, for Emacs hash-table
functions is to start the function name with `hash-table'.
That accords with the convention of putting the object