Artie Gold wrote:This is an FAQ classic: you have to capture the return value from sort.
> (defun build-occurences-alist (the-list)
> ; the-alist is the result
> (let ((the-alist nil))
> (flet ((update-alist (key)
> ; have we dealt with this symbol already?
> (let ((pos (assoc key the-alist)))
> (if pos
> ; we have, so increment the count
> (incf (cdr pos))
> ; we haven't, so create an entry
> (push (cons key 1) the-alist)))))
> ; map across the supplied list
> (mapc #'update-alist the-list)
> ; I can't get the sort to work for some reason
> ;(sort the-alist #'> :key #'cdr)
> Aside from the fact that I can't seem to get the SORT to work (any clues
Remember, there is no such thing as a list. The local variable the-alist
is bound to a cons cell (the first of the list before the sort). after
the sort (since you do not code "(setf the-alist (sort the-alist....")
it naturally is still bound to the same cons cell, no matter where that
cons cell now sits in the structure which followed it until sort
destructively rearranged things.
Of course in the example above it so happens you do not need the "(setf
Your Project Here! http://alu.cliki.net/Industry%20Application
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.