;; Hi. I would like to invert an alist of the form ;; ;; ((reference-1 referent-a referent-b...) (reference-2 referent-c ...)...) ;; ;; to
another alist of the form ;; ;; ((referent-a reference-1) (referent-b reference-1) ;; (referent-c reference-2) ...) ;; ;; I have gotten something to work but it's so stupefyingly *UGLY* that I ;; just know someone out there can demonstrate a more better beautiful ;; elegant
means of achieving the same result. ;; ;; [ I'm working in emacs-lisp
with the 'cl' package, so the code below ;; ought to be reasonably close
to Common Lisp...] ;; ;; ;; Mind you, I am teaching myself lisp and THIS
I'd do it something like this:
(defun invert-alist (alist)
(loop for list in test
for reference = (first list)
appending (loop for referent in (cdr list)
collect (list referent reference))))
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 299 |
Nodes: | 16 (2 / 14) |
Uptime: | 26:33:36 |
Calls: | 6,681 |
Calls today: | 4 |
Files: | 12,222 |
Messages: | 5,342,295 |
Posted today: | 2 |