summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-05-13 18:43:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-05-13 18:43:02 -0700
commitcdf79f2907cab5aa410ad47934f0374254386220 (patch)
treedc806ed600d1defd3eaf8ed1965a8987d8dfaaa9 /share
parent0786f1422cf0a949fb0e0daf98852123ced19c9a (diff)
downloadtxr-cdf79f2907cab5aa410ad47934f0374254386220.tar.gz
txr-cdf79f2907cab5aa410ad47934f0374254386220.tar.bz2
txr-cdf79f2907cab5aa410ad47934f0374254386220.zip
lib: sort becomes non-destructive; nsort introduced.
I'm fixing a historic mistake copied from ANSI Lisp, which trips up language newcomers and sometimes even experienced users. The function innocently named sort will now return newly allocated structure. The function previously called sort will be available as nsort (non-consing/allocating sort). The shuffle function also becomes pure, and is accompanied by nshuffle. * eval (me_op): Continue to use destructive sort in this legacy code that is only triggered in very old compat mode. (eval_init): Registered nsort and nshuffle. * lib.c (nsort, nshuffle): New functions introduced, closely based on sort and shuffle. (sort, shuffle): Rewritten to avoid destructive behavior: work by copying the input and calling destructive counterparts. (sort_group): Continue to use destructive sort, which is safe; the structure is locally allocated. The sort_group function has pure semantics. (grade): Likewise. * lib.h (nsort, nshuffle): Declared. * share/txr/stdlib/getopts.tl (opthelp): Replace an instance of the (sort (copy-list ...)) pattern with just (sort ...). * tags.tl (toplevel): Continue to use destructive sort to sort tags before writing the tag file; the lifetime of the tags list ends when the file is written. * tests/010/seq.txr: Switch some sort calls to nsort to keep test case working. * txr.1: Documented.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/getopts.tl4
1 files changed, 2 insertions, 2 deletions
diff --git a/share/txr/stdlib/getopts.tl b/share/txr/stdlib/getopts.tl
index b98a76dc..db8f793f 100644
--- a/share/txr/stdlib/getopts.tl
+++ b/share/txr/stdlib/getopts.tl
@@ -269,8 +269,8 @@
opr.(parse-opts args)))
(defun opthelp (opt-desc-list : (stream *stdout*))
- (let ((sorted [sort (copy-list (remove-if (op null @1.helptext)
- opt-desc-list)) :
+ (let ((sorted [sort (remove-if (op null @1.helptext)
+ opt-desc-list) :
(do if @1.long @1.long @1.short)])
(undocumented (keep-if (op null @1.helptext) opt-desc-list)))
(put-line "\nOptions:\n")