Tutorial by Examples

Hash tables are created by make-hash-table: (defvar *my-table* (make-hash-table)) The function may take keyword parameters to further specify the behavior of the resulting hash table: test: Selects the function used to compare keys for equality. Maybe a designator for one of the functions eq,...
(defun print-entry (key value) (format t "~A => ~A~%" key value)) (maphash #'print-entry *my-table*) ;; => NIL Using maphash allows to iterate over the entries of a hash table. The order of iteration is unspecified. The first argument is a function accepting two parameters: ...
The loop macro supports iteration over the keys, the values, or the keys and values of a hash table. The following examples show possibilities, but the full loop syntax allows more combinations and variants. Over keys and values (let ((ht (make-hash-table))) (setf (gethash 'a ht) 1 (g...
The keys and values of a hash table can be iterated over using the macro with-hash-table-iterator. This may be a bit more complex than maphash or loop, but it could be used to implement the iteration constructs used in those methods. with-hash-table-iterator takes a name and a hash table and binds...

Page 1 of 1