From: Paulo J. Matos aka PDestroy
Subject: Maphash variable not used
Date: 
Message-ID: <3B195791.6722946B@netcabo.pt>
Hi,
I'm using many times maphash and I use it for example has the following
several times:
(maphash #'(lambda (key val)
		 (dolist (elem dirlist)
			 (let ((post (pos-triple val elem)))
			   (if (and (pos-val-p (second post))
				    (pos-val-p (third post))
				    (mov-legal estado val elem))
			       (setf sucessores (cons (move-peca estado val elem)
sucessores))))))
	     estado)

And has you can see in this example, I do not use Key.
This is told me by the compiler when I try to compile the file. It's a
warning, anyway, I hate and I'm sick of them... How can I remove the
warning?

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!"   |
+-----------------------------------------------------------------+

I name my wife: Gala, Galuska, Gradiva; Oliva, for the oval shape of her
face and the colour of her skin; Oliveta, diminutive for Olive; and its
delirious derivatives Oliueta, Oriueta, Buribeta, Buriueteta, Suliueta,
Solibubuleta, Oliburibuleta, Ciueta, Liueta. I also call her Lionette,
because when she hets angry she roars like the Metro-Goldwyn-Mayer Lion.
           - Dali, Salvador

From: Tim Moore
Subject: Re: Maphash variable not used
Date: 
Message-ID: <9fe4di$63q$0@216.39.145.192>
On Sat, 2 Jun 2001, Paulo J. Matos aka PDestroy wrote:

> Hi,
> I'm using many times maphash and I use it for example has the following
> several times:
> (maphash #'(lambda (key val)
	       (declare (ignore key))
> 		 (dolist (elem dirlist)
> 			 (let ((post (pos-triple val elem)))
> 			   (if (and (pos-val-p (second post))
> 				    (pos-val-p (third post))
> 				    (mov-legal estado val elem))
> 			       (setf sucessores (cons (move-peca estado val elem)
> sucessores))))))
> 	     estado)
> 
> And has you can see in this example, I do not use Key.
> This is told me by the compiler when I try to compile the file. It's a
> warning, anyway, I hate and I'm sick of them... How can I remove the
> warning?

With (declare (ignore ...)).  See above.

Tim
From: Pierre R. Mai
Subject: Re: Maphash variable not used
Date: 
Message-ID: <873d9hnldv.fsf@orion.bln.pmsf.de>
"Paulo J. Matos aka PDestroy" <········@netcabo.pt> writes:

> Hi,
> I'm using many times maphash and I use it for example has the following
> several times:
> (maphash #'(lambda (key val)
> 		 (dolist (elem dirlist)
> 			 (let ((post (pos-triple val elem)))
> 			   (if (and (pos-val-p (second post))
> 				    (pos-val-p (third post))
> 				    (mov-legal estado val elem))
> 			       (setf sucessores (cons (move-peca estado val elem)
> sucessores))))))
> 	     estado)
> 
> And has you can see in this example, I do not use Key.
> This is told me by the compiler when I try to compile the file. It's a
> warning, anyway, I hate and I'm sick of them... How can I remove the
> warning?

Others have pointed out the ignore declaration, which you should look
up in the Hyperspec and learn about, because it is valuable in other
contexts, too.  While you are at it, you might want to learn about the
ignorable declaration, too, which is helpful, when you don't know
whether the variable will be used or not (that can happen when writing
macros, for example).

In this particular scenario, though, I would rather rewrite your code
to use LOOP, which let's you specify that you only iterate over the
hash values more directly.  Below you can find a rewritten version of
your code, which has some additional (uninvited) style improvements:

- Use WHEN/UNLESS instead of IF when there is only one clause
- Use PUSH instead of (setf x (cons y x))

(loop for val being the hash-values of estado
      do
      (dolist (elem dirlist)
        (let ((post (pos-triple val elem)))
          (when (and (pos-val-p (second post))
                     (pos-val-p (third post))
                     (mov-legal estado val elem))
            (push (move-peca estado val elem) sucessores)))))

Furthermore you might want to consider whether you can create a more
concise predicate function, rather than the and of 2 pos-val-p and one
mov-legal checks.

Regs, Pierre.

-- 
Pierre R. Mai <····@acm.org>                    http://www.pmsf.de/pmai/
 The most likely way for the world to be destroyed, most experts agree,
 is by accident. That's where we come in; we're computer professionals.
 We cause accidents.                           -- Nathaniel Borenstein