B. Pym wrote:
Kenny Tilton wrote:
(defun p2b (pairs &key ((:test test) #'eql))
"((A 1) (A 2) (B 2) (C 2) (C 3)) ==> ((A 1 2) (B 2) (C 2 3))"
(loop with bunch = nil
for (one two) in pairs
do (push two (cdr (or (assoc one bunch :test test)
(car (push (list one) bunch)))))
finally (return bunch)))
Testing:
(p2b '((A 1) (A 2) (B 2) (C 2) (C 3) (A 88)))
===>
((C 3 2) (B 2) (A 88 2 1))
Gauche Scheme
Let's use a collector that collects into an association-list.
(let ((a (malistbag)))
(for-each
(lambda(xs) (apply a `(,@xs ,cons ())))
'((A 1) (A 2) (B 2) (C 2) (C 3) (A 88)))
(a))
Given:
Kenny Tilton wrote:
(defun p2b (pairs &key ((:test test) #'eql))
"((A 1) (A 2) (B 2) (C 2) (C 3)) ==> ((A 1 2) (B 2) (C 2 3))"
(loop with bunch = nil
for (one two) in pairs
do (push two (cdr (or (assoc one bunch :test test)
(car (push (list one) bunch)))))
finally (return bunch)))
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 05:31:16 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
921 files (14,318M bytes) |
| Messages: | 264,603 |