From 20e8339c8976d8f5c4ccd5700724c38945d69699 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 14 May 2020 06:30:55 -0700 Subject: sort: prudently make it subject to compat value * eval.c (eval_init): If opt_compat is 237 or less, make sort and shuffle destructive. * share/txr/stdlib/getopts.tl (opthelp): Revert previous change, restoring use of copy-list and use nsort instead of sort, so the function is not affected by the 237 compatibility being turned on. * txr.1: Add compatibility notes. --- eval.c | 6 ++++-- share/txr/stdlib/getopts.tl | 6 +++--- txr.1 | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/eval.c b/eval.c index 4d0cc137..2d547d44 100644 --- a/eval.c +++ b/eval.c @@ -6893,9 +6893,11 @@ void eval_init(void) reg_fun(intern(lit("improper-plist-to-alist"), user_package), func_n2(improper_plist_to_alist)); reg_fun(intern(lit("merge"), user_package), func_n4o(merge_wrap, 2)); reg_fun(intern(lit("nsort"), user_package), func_n3o(nsort, 1)); - reg_fun(intern(lit("sort"), user_package), func_n3o(sort, 1)); + reg_fun(intern(lit("sort"), user_package), + func_n3o(if3(opt_compat && opt_compat <= 237, nsort, sort), 1)); reg_fun(intern(lit("nshuffle"), user_package), func_n1(nshuffle)); - reg_fun(intern(lit("shuffle"), user_package), func_n1(shuffle)); + reg_fun(intern(lit("shuffle"), user_package), + func_n1(if3(opt_compat && opt_compat <= 237, nshuffle, shuffle))); reg_fun(intern(lit("find"), user_package), func_n4o(find, 2)); reg_fun(intern(lit("rfind"), user_package), func_n4o(rfind, 2)); reg_fun(intern(lit("find-if"), user_package), func_n3o(find_if, 2)); diff --git a/share/txr/stdlib/getopts.tl b/share/txr/stdlib/getopts.tl index db8f793f..5a937f84 100644 --- a/share/txr/stdlib/getopts.tl +++ b/share/txr/stdlib/getopts.tl @@ -269,9 +269,9 @@ opr.(parse-opts args))) (defun opthelp (opt-desc-list : (stream *stdout*)) - (let ((sorted [sort (remove-if (op null @1.helptext) - opt-desc-list) : - (do if @1.long @1.long @1.short)]) + (let ((sorted [nsort (copy-list (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") (each ((od sorted)) diff --git a/txr.1 b/txr.1 index f33024ad..a1a21800 100644 --- a/txr.1 +++ b/txr.1 @@ -32632,6 +32632,13 @@ The behavior of .code sort is not specified for hashes whose contents do not conform to this convention. +Note: +.code nsort +was introduced in \*(TX 238. Prior to that version, +.code sort +behaved like +.codn nsort . + .coNP Function @ grade .synb .mets (grade < sequence >> [ lessfun <> [ keyfun ]]) @@ -32719,6 +32726,13 @@ were made using .code copy and then that copy were shuffled in-place and returned. +Note: +.code nshuffle +was introduced in \*(TX 238. Prior to that version, +.code shuffle +behaved like +.codn nshuffle . + .coNP Function @ sort-group .synb .mets (sort-group < sequence >> [ keyfun <> [ lessfun ]]) @@ -73404,6 +73418,12 @@ of these version values, the described behaviors are provided if is given an argument which is equal or lower. For instance .code "-C 103" selects the behaviors described below for version 105, but not those for 102. +.IP 237 +Compatibility values of 237 or lower restore the destructive behavior of the +.code sort +and +.code shuffle +functions. .IP 234 In \*(TX 234 and older versions, the exception throwing functions .code throw -- cgit v1.2.3