[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Any interest in a function like this to add to subr.el?
From: |
John Wiegley |
Subject: |
Re: Any interest in a function like this to add to subr.el? |
Date: |
Tue, 18 Oct 2016 14:25:14 -0700 |
User-agent: |
Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (darwin) |
>>>>> "DG" == Dmitry Gutov <address@hidden> writes:
GD> Then I agree that we want a function like that. We'd want a destructive
GD> version of it as well, though.
Yes, good idea! How about something like this:
(defun sort-on* (seq predicate accessor)
"Sort SEQ using PREDICATE applied to values returned by ACCESSOR.
This is a destructive version of `sort-on', which attempts to
reuse storage as much as possible."
(let ((seq2 seq))
(while seq2
(setcar seq2 (cons (funcall accessor (car seq2)) (car seq2)))
(setq seq2 (cdr seq2))))
(setq seq (sort* seq #'(lambda (x y) (funcall predicate (car x) (car y)))))
(let ((seq2 seq))
(while seq2
(setcar seq2 (cdar seq2))
(setq seq2 (cdr seq2)))
seq))
--
John Wiegley GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2
Re: Any interest in a function like this to add to subr.el?, Andy Moreton, 2016/10/19