From: Paulo J. Matos aka PDestroy
Subject: with-hash-table-iterator
Date: 
Message-ID: <3B112F40.787293C3@netcabo.pt>
Hi all,
I'm sure this is what I want. I want to iterate through all the elements
of a list and do something with them,with-hash-table-iterator is the
function to use but I'm not being able to understand how to use it. I've
read ANSI Common Lisp by P. Graham but he doesn't have an example on it.
I'm not understand what is the symbol argument.

Any help would be appreciated.

Best regards,
-- 
+------------------Paulo J. Matos aka PDestroy--------------------+
|  ICQ # 361853  |  http://www.pdestroy.net | ········@netcabo.pt |
|  http://iascp.sourceforge.net  |  http://mega.ist.utl.pt/~pocm  |
|  "Fixed width font LIVEZ!"     |  "Portability came to rule!"   |
+-----------------------------------------------------------------+

Life's no picnic and then... you die!
           - Anonymous

From: Steven M. Haflich
Subject: Re: with-hash-table-iterator
Date: 
Message-ID: <3B113AB7.DC869836@pacbell.net>
"Paulo J. Matos aka PDestroy" wrote:
> 
> I'm sure this is what I want. I want to iterate through all the elements
> of a list and do something with them,with-hash-table-iterator is the
> function to use

Perhaps there is a language problem here, but with-hash-table-iterator
iterates through the entries in a hash tablem, not the elements of a list.
It iterate over the elements of a list one would typically use dolist
or loop ... for.


> but I'm not being able to understand how to use it. I've
> read ANSI Common Lisp by P. Graham but he doesn't have an example on it.
> I'm not understand what is the symbol argument.

Graham does not cover everything in the language.  For accurate and
complete reference, see the ANSI specification for the CL language
available online in a variety of places.  Here is a direct link to the
with-hash-table-iterator page:

http://www.franz.com/support/documentation/6.0/ansicl/dictentr/with-has.htm

At www.lisp.org you can find pointers to a downloadable html version of the
full ANS and also versions of CLtL2, which, while out of date relative to
the ANS, is better at teaching the language.  The ANS is a guru document
not intended to be fully understandable by beginners in the language.
Follow the "references" link.
From: Kent M Pitman
Subject: Re: with-hash-table-iterator
Date: 
Message-ID: <sfwlmnihfc9.fsf@world.std.com>
"Paulo J. Matos aka PDestroy" <········@netcabo.pt> writes:

> I'm sure this is what I want. I want to iterate through all the elements
> of a list and do something with them,with-hash-table-iterator is the
> function to use but I'm not being able to understand how to use it. I've
> read ANSI Common Lisp by P. Graham but he doesn't have an example on it.
> I'm not understand what is the symbol argument.

You say you want to iterate through the elements of a list.  If so, DOLIST
or LOOP is probably what you want. e.g.,

 (dolist (x '(1 2 3)) (print x))
 1
 2
 3

or

 (loop for x in '(1 2 3)
       collect (* x 2))
 => (2 4 6)


Iteration across a hash table can easily be accomplished by LOOP's 
keywords for that. e.g.,

 (loop for x being the hash-keys of h do (print x))

 (let ((h (make-hash-table)))
   ;; Set up the table with some sample data.
   (dotimes (i 10) (setf (gethash i h) (format nil "~r" i)))
   ;; Now go pick up that data.
   (loop for k being the hash-keys   of h
         for v being the hash-values of h
         do (print (list k v))))

 (0 "zero") 
 (7 "seven") 
 (6 "six") 
 (5 "five") 
 (4 "four") 
 (3 "three") 
 (2 "two") 
 (9 "nine") 
 (1 "one") 
 (8 "eight") 
 
You probably don't want to use WITH-HASH-TABLE-ITERATOR unless you're
implementing the low-level details of something like the LOOP macro
or doing a very unusual kind of control structure that steps the elements
of the table orthogonally to your other control patterns.  My guess is
that since you are not able to puzzle out the arguments to this, you don't
have a problem of sufficient complexity to need this.

CLHS does have a worked example, though, if you really need one.

The other facility which is easier to use and doesn't require using LOOP
is MAPHASH.  I usually prefer it to LOOP when I have a problem simple enough
to allow it, such as the one above, actually:

 (let ((h (make-hash-table)))
   ;; Set up the table with some sample data.
   (dotimes (i 10) (setf (gethash i h) (format nil "~r" i)))
   ;; Now go pick up that data.
   (maphash #'(lambda (key val) (print (list key val))) h))

 (0 "zero") 
 (7 "seven") 
 (6 "six") 
 (5 "five") 
 (4 "four") 
 (3 "three") 
 (2 "two") 
 (9 "nine") 
 (1 "one") 
 (8 "eight") 
From: Paulo J. Matos aka PDestroy
Subject: Re: with-hash-table-iterator
Date: 
Message-ID: <3B1141B2.38897C37@netcabo.pt>
Hi, Just a thing just below (..."the elements of a list"...) I didn't
meant a list of course, I meant a hash table... 
:)

Best regards,
Paulo

"Paulo J. Matos aka PDestroy" wrote:
> 
> Hi all,
> I'm sure this is what I want. I want to iterate through all the elements
> of a list and do something with them,with-hash-table-iterator is the
> function to use but I'm not being able to understand how to use it. I've
> read ANSI Common Lisp by P. Graham but he doesn't have an example on it.
> I'm not understand what is the symbol argument.
> 
> Any help would be appreciated.
> 

-- 
+------------------Paulo J. Matos aka PDestroy--------------------+
|  ICQ # 361853  |  http://www.pdestroy.net | ········@netcabo.pt |
|  http://iascp.sourceforge.net  |  http://mega.ist.utl.pt/~pocm  |
|  "Fixed width font LIVEZ!"     |  "Portability came to rule!"   |
+-----------------------------------------------------------------+

Life's no picnic and then... you die!
           - Anonymous