[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Maphash



    Date: Thu, 19 May 1983  00:23 EDT
    From: Scott E. Fahlman <Fahlman@CMU-CS-C>
    Since MAPHASH returns NIL, there is no elegant way to turn the
    contents of a hashtable into a list.  What would people think of
    flushing MAPHASH and replacing it with DO-HASH ?

Is	(defun hash-table-to-alist (ht)
	  (let ((alist nil))
	    (do-hash ((key value) ht)
	      (push (cons key value) alist))
	    alist))

more elegant than

	(defun hash-table-to-alist (ht)
	  (let ((alist nil))
	    (maphash #'(lambda (key value)
			 (push (cons key value) alist))
		     ht)
	    alist))
?

You aren't allowed to base your decision on the fact that both your CL
implementation and my CL implementation are currently in violation of
the standard, such that the latter version doesn't work unless alist is
declared special.  You also aren't allowed to base your decision on the
fact that the best way to do this operation is with LOOP.