2 questions: make-list and hash-table
Hello,Question 1:
when I create a list with like
(setf a (make-list 10 :initial-element '(0 0)))
then the command
setf (second (nth 4 a)) 3)
creates var _a_ as
((0 3) (0 3) (0 3) (0 3) (0 3) (0 3) (0 3) (0 3) (0 3) (0 3))
why does setf (second (nth 4 a)) 3) concern every nth in the sense of (first (second (nth x a)) ?
Having read CLtL p. 418 (and Graham) I simply don't understand the situation.
Question 2:
I try to figure out the details of the loop macro with hash-tables (I know of other possibilities but now I'm interested only in this).
Some tutorials taught me that this works (and it does in LW):
- (setf h (make-hash-table))
- (setf (gethash 'a h) 1)
- (setf (gethash 'b h) 2)
- loop for k being the hash-key of h do (print k))
But when I try to get the hash-val together with the key-val with
(loop for k being the hash-key using (hash-value v) of h do (format t "~a ~a~%" k v))
then I get an error message from LW: Error: Unknown LOOP keyword in (... LOOP::OF H DO (FORMAT T "~a ~a~%" K V)).
Having read the passages in CLtL p. 723 I can't find a solution (in the sense of a very similar formulation - not maphash or other loop-constructions).
Many thanks for any advice.
Best,
Max