Opened 13 years ago
Closed 13 years ago
#207 closed defect (invalid)
'sort' function truncates lists
Reported by: | Brian | Owned by: | gb |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | ANSI CL Compliance | Version: | unspecific |
Keywords: | Cc: |
Description
Welcome to Clozure Common Lisp Version 1.1-r7809 (DarwinPPC32)!
? (let ((x '(1 2 3)))
(sort x #'<) x)
(1 2 3) ? (let ((x '(1 3 2)))
(sort x #'<) x)
(1 2 3) ? (let ((x '(2 1 3)))
(sort x #'<) x)
(2 3) ? (let ((x '(2 3 1)))
(sort x #'<) x)
(2 3) ? (let ((x '(3 1 2)))
(sort x #'<) x)
(3) ? (let ((x '(3 2 1)))
(sort x #'<) x)
(3)
I know that 'sort' is a "destructive" operation, but I think this goes too far.
Note that the problem does not arise when the argument is a vector rather than a list:
? (let ((x '#(3 2 1)))
(sort x #'<) x)
#(1 2 3)
Also, 'stable-sort' exhibits the same behavior.
Change History (2)
comment:1 Changed 13 years ago by Brian
comment:2 Changed 13 years ago by gb
- Resolution set to invalid
- Status changed from new to closed
This is absolutely, positively not a bug.
A good explanation of the issues involved can be found in section 3-3 of
http://www.faqs.org/faqs/lisp-faq/part3/
There are also issues related to using destructive operations (like SORT) on quoted constants. Consider:
? (defun maybe-sort-constant-list (sort-it) (let* ((x '(3 2 1))) (when sort-it (sort x #'<)) x)) MAYBE-SORT-CONSTANT-LIST ? (maybe-sort-constant-list t) (3) ? (maybe-sort-constant-list nil) (3)
It is worth trying to understand what's happening here.
Sorry for the lame formatting of the original post. Here's what I hope is a more intelligible version:
Welcome to Clozure Common Lisp Version 1.1-r7809 (DarwinPPC32)!
I know that 'sort' is a "destructive" operation, but I think this goes too far.
Note that the problem does not arise when the argument is a vector rather than a list:
Also, 'stable-sort' exhibits the same behavior.