(symbolp OBJECT) (intern-soft NAME &optional OBARRAY) (intern STRING &optional OBARRAY) (unintern NAME &optional OBARRAY) (mapatoms FUNCTION &optional OBARRAY) (symbol-name SYMBOL) (symbol-value SYMBOL) (set SYMBOL NEWVAL) (setq SYM VAL SYM VAL ...) (symbol-function SYMBOL) (fset SYMBOL DEFINITION) (symbol-plist SYMBOL) (get SYMBOL PROPNAME) (put SYMBOL PROPNAME VALUE)
(defun hash-string (str) (let ((hash 0) c) (dotimes (i (length str)) (setq c (aref str i)) (if (> c #o140) (setq c (- c 40))) (setq hash (+ (setq hash (lsh hash 3)) (lsh hash -28) c))) hash))
(let ((len 10) str hash) (setq foo (make-vector len 0)) (dotimes (i (1+ len)) (setq str (char-to-string (+ ?a i)) hash (% (hash-string str) len)) (message "I put %s in slot %d" str hash) (if (eq (aref foo hash) 0) (intern str foo) (message "I found %S is already taking the slot: %S" (aref foo hash) foo) (intern str foo) (message "Now I'am in the slot too: %S" foo))))
在我这里的输出是:
I put a in slot 7 I put b in slot 8 I put c in slot 9 I put d in slot 0 I put e in slot 1 I put f in slot 2 I put g in slot 3 I put h in slot 4 I put i in slot 5 I put j in slot 6 I put k in slot 7 I found a is already taking the slot: [d e f g h i j a b c] Now I'am in the slot too: [d e f g h i j k b c]