2

I have the following, I'm iterating over a hashmap using maphash. The lambda function that process each element in the hashmap receives two arguments, a key and a value. But I never use the value, so, when compiling I receive a warning. How can I fix this warning?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Luis Alves
  • 1,286
  • 12
  • 32

2 Answers2

3
? (defun foo (a b) (+ a 2))
;Compiler warnings :
;   In FOO: Unused lexical variable B
FOO

? (defun foo (a b)
    (declare (ignore b))
    (+ a 2))
FOO
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
2

Rainer's already point out the (declare (ignore ...)) (which was already present in another question, actually). If you're interested in another way to iterate over hash table keys (or values), you can use loop:

(let ((table (make-hash-table)))
  (dotimes (x 5) 
    (setf (gethash x table) (format nil "~R" x)))
  (values 
   (loop for value being each hash-value of table
      collect value)
   (loop for key being each hash-key of table
      collect key)))
;=> 
; ("zero" "one" "two" "three" "four")
; (0 1 2 3 4)
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353