From 2fccb10283aae350ced4db70fcddcc95e59e503a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 10 Feb 2014 05:12:14 -0800 Subject: Relaxed behavior: don't throw errors for impossible permutations, but return an empty list. * eval.c (perm_init_common): Do not throw error; return a nil state if permutation length exceeds sequence length. (perm_vec, perm_list, perm_str): Check for null return from perm_init_common and return empty list. (k_conses): Do not throw error; return empty list. (comb_list_gen_fun): Check for nil value out of k_conses. (comb): For vectors and strings, check length against k and return nil if necessary. For lists, comb_list_gen_fun handles it. * txr.1: Section order rearranged, and updated. --- txr.1 | 66 +++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 29 deletions(-) (limited to 'txr.1') diff --git a/txr.1 b/txr.1 index 195dd441..f7b65d7d 100644 --- a/txr.1 +++ b/txr.1 @@ -7869,6 +7869,37 @@ cached inside and returned, becoming the return value of the force function call. If the force function is invoked additional times on the same promise, the cached value is retrieved. +.SS Function perm + +.TP +Syntax: + + (perm []) + +.TP +Description: + +The rperm function returns a lazy list which consists of all +length permutations of formed by items taken from . +The permutations do not use any element of more than once. + +Argument , if present, must be a positive integer, and must be a +sequence. + +If is not present, then its value defaults to the length of : +the list of the full permutations of the entire sequence is returned. + +The permutations in the returned list are sequences of the same kind as . + +If is zero, then a list containing one permutation is returned, and that +permutations is of zero length. + +If exceeds the length of , then an empty list is returned, +since it is impossible to make a single non-repeating permutation that +requires more items than are available. + +The permutations are lexicographically ordered. + .SS Function rperm .TP @@ -7909,34 +7940,8 @@ Examples: (rperm '(0 1 2) 2) -> ((0 0) (0 1) (0 2) (1 0) (1 1) (1 2) (2 0) (2 1) (2 2)) -.SS Function perm - -.TP -Syntax: - - (perm []) - -.TP -Description: - -The rperm function returns a lazy list which consists of all -length permutations of formed by items taken from . -The permutations do not use any element of more than once. -Argument , if present, must be a positive integer no greater -than the length of , and must be a sequence. - -If is not present, then its value defaults to the length of : -the list of the full permutations of the entire sequence is returned. - -The permutations in the returned list are sequences of the same kind as . - -If is zero, then a list containing one permutation is returned, and that -permutations is of zero length. - -The permutations are lexicographically ordered. - -.SS Functions comb and rcomb +.SS Function comb .TP Syntax: @@ -7952,14 +7957,17 @@ length non-repeating combinations formed by taking items taken from element of more than once. If contains no duplicates, then the combinations contain no duplicates. -Argument must be a nonnegative integer no greater than the length of -, and must be a sequence. +Argument must be a nonnegative integer, and must be a sequence. The combinations in the returned list are sequences of the same kind as . If is zero, then a list containing one combination is returned, and that permutations is of zero length. +If exceeds the length of , then an empty list is returned, +since it is impossible to make a single non-repeating combination that +requires more items than are available. + The combinations are lexicographically ordered. .SS Function rcomb -- cgit v1.2.3