Re: the sort function in lisp (destructive)
- From: Rainer Joswig <joswig@xxxxxxx>
- Date: Sun, 06 Jan 2008 17:38:04 +0100
In article <4780e8b3$0$90268$14726298@xxxxxxxxxxxxxxx>,
"Alex Mizrahi" <udodenko@xxxxxxxxxxxxxxxxxxxxx> wrote:
i agree that it would be more newbie-friendly to have either non-destructive
sort by default or sortf,
but Common Lisp is not a newbie-oriented language, and more experienced Lisp
programmers use SORT without problems (or they can easily define function or
macro that fits them better).
Another alternative would be a SORT that does not reorder the CONS cells,
but the CARs of the CONS cells. SORT the list into another
data structure and then set the list's CARs from there.
Though even that would not be that useful.
(defun my-sort (list predicate)
(map-into list
#'identity
(sort (copy-list list) predicate)))
(let ((l1 (list 'd 'e 'a 'f 'x 'h)))
(let ((l2 (sort l1 #'string<)))
(values l1 l2)))
->
(D E F H X)
(A D E F H X)
(let ((l1 (list 'd 'e 'a 'f 'x 'h)))
(let ((l2 (my-sort l1 #'string<)))
(values l1 l2)))
->
(A D E F H X)
(A D E F H X)
if newbies will spend some hours debugging weird SORT behaviour it would be
better for them -- that way they'll understand understand faster what does
word "destructive" mean and how variables do work.
--
http://lispm.dyndns.org/
.
- Follow-Ups:
- Re: the sort function in lisp (destructive)
- From: Alex Mizrahi
- Re: the sort function in lisp (destructive)
- From: John Thingstad
- Re: the sort function in lisp (destructive)
- References:
- Re: the sort function in lisp (destructive)
- From: Alex Mizrahi
- Re: the sort function in lisp (destructive)
- Prev by Date: Re: dolist style
- Next by Date: Re: About differences between #: and : in defpackage
- Previous by thread: Re: the sort function in lisp (destructive)
- Next by thread: Re: the sort function in lisp (destructive)
- Index(es):
Relevant Pages
|