[COLUG] Re: Lisp variable scope
David Riggs
dariggs at humnet.ucla.edu
Sat Dec 2 20:01:27 EST 2006
> From: Steven Huwig <shuwig at columbus.rr.com>
> I think your trouble is using '("a" . 0) instead of (cons "a" 0).
Dear Steven,
Thank you.
YES, that's it! Now the values are reset to zero each time the function
is called. But why? Apparently there is something fundamental that I
still do not get about lists, and Steele does not explain it (as far as
I can tell).
> at the top of http://wiki.alu.org/Lisp_Gotchas .
Thanks for that list.
But, do you know why these apparently identical moves produce such
different result?
Gratefully yours,
David Riggs
>
>
>>I have a little function to search through some data and count up
>>occurances of found items, which I keep track of with an a-list.
>
>
> Would this be something like:
>
> (defun count-items (items)
> (let ((counts (make-hash-table)))
> (dolist (item items)
> (puthash item (1+ (gethash item counts 0)) counts))
> (let ((results '()))
> (maphash (lambda (k v) (push (cons k v) results)) counts)
> results)))
>
> (count-items '(a b a a b c d b d))
> ((d . 2) (c . 1) (b . 3) (a . 3))
>
> -- Steve
>
>
> ------------------------------
>
> _______________________________________________
> colug432 mailing list
> colug432 at colug.net
> http://www.colug.net/mailman/listinfo/colug432
>
>
> End of colug432 Digest, Vol 24, Issue 1
> ***************************************
>
More information about the colug432
mailing list