Subject: Re: Excerise in Graham's ANSI Common Lisp
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 20 Jul 2006 04:41:36 -0500
Newsgroups: comp.lang.lisp
Message-ID: <7rednZnHIqBN0iLZnZ2dnUVZ_o2dnZ2d@speakeasy.net>
Bill Atkins <batkins57@gmail.com> wrote:
+---------------
| Rob Warnock wrote:
| > (defun hash-table-alist (table)
| >   (let (result)
| > 	(do-hash (key value table result)
| > 	  (push (cons key value) result))))
| 
| What is DO-HASH?
+---------------

Oops!! My bad. Sorry for not spotting that earlier.
It seems that DO-HASH is a CMUCL extension:

    cmu> (describe 'do-hash)
    DO-HASH is an external symbol in the EXTENSIONS package.
    Macro-function: #<Byte function (:MACRO DO-HASH) {28F9EEE9}>
    Macro documentation:
      DO-HASH (Key-Var Value-Var Table [Result]) Declaration* Form*
       Iterate over the entries in a hash-table.
    ...

that expands into a call of WITH-HASH-TABLE-ITERATOR, very
similar to the example definition of MAP-HASH in the CLHS
entry for WITH-HASH-TABLE-ITERATOR, except that instead of
FUNCALL'ing a function it executes a &BODY.

+---------------
| (defun hash-table-to-alist (table)
|   (let (result)
|     (maphash (lambda (k v) (push (cons k v) result))
|              table)
|     result))
+---------------

Yes, that's an equivalent standard-conformant way to define it.


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607