Lisp sort function key

Viewed 856

I'm trying to sort a list that looks something like this:

(defvar my-list '((:x 1 :y something) (:x 5 :y something) (:x 19 :y something)))

I'm trying to sort it by the value in :x. I could do that like this

(sort my-list #'> :key #'second)

but I would very much prefer to use the getf function instead of second, but I can't figure out how to pass :x as a parameter.

From what I can gather just #'getf returns (getf ((:x 1 :y something) '(:x 5 :y something) (:x 19 :y something)) [external]. How would I go about passing :x as the second parameter?

The only way I could think of is to create a wrapper-function for getf, which only takes a list as a parameter and passes in :x by default. There must be a better way though.

2 Answers
Related