32 lines
732 B
Text
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)
|