RosettaCodeData/Task/Sort-an-array-of-composite-structures/ACL2/sort-an-array-of-composite-structures.acl2
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

32 lines
732 B
Text

(defun insert-by-key (o os key)
(cond ((endp os) (list o))
((< (cdr (assoc key o))
(cdr (assoc key (first os))))
(cons o os))
(t (cons (first os)
(insert-by-key o (rest os) key)))))
(defun isort-by-key (os key)
(if (endp os)
nil
(insert-by-key (first os)
(isort-by-key (rest os) key)
key)))
(isort-by-key
'(((name . "map")
(weight . 9)
(value . 150))
((name . "compass")
(weight . 13)
(value . 35))
((name . "water")
(weight . 153)
(value . 200))
((name . "sandwich")
(weight . 50)
(value . 60))
((name . "glucose")
(weight . 15)
(value . 60)))
'value)