diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-05-29 07:48:00 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-05-29 07:48:00 -0700 |
commit | 683e006094b166173fe4f1cd0338708b5defa71c (patch) | |
tree | c8d8c34a6f9d2e78a88ab7a8160813d568c0aeb8 | |
parent | f96d3b8781ee716cff050ca550a9086032c1768c (diff) | |
download | txr-683e006094b166173fe4f1cd0338708b5defa71c.tar.gz txr-683e006094b166173fe4f1cd0338708b5defa71c.tar.bz2 txr-683e006094b166173fe4f1cd0338708b5defa71c.zip |
combi: consolidate k argument check.
* combi.c (check_k): New static function.
(perm, rperm, comb, rcomb): Replace copy pasted code
with call to check_k.
-rw-r--r-- | combi.c | 38 |
1 files changed, 14 insertions, 24 deletions
@@ -37,6 +37,16 @@ #include "hash.h" #include "combi.h" +static void check_k(val k, val self) +{ + if (!integerp(k)) + type_mismatch(lit("~a: ~s is not an integer"), self, k, nao); + + if (minusp(k)) + uw_throwf(numeric_error_s, lit("~a: ~s is not a positive integer"), + self, k, nao); +} + static val perm_while_fun(val state) { val self = lit("perm"); @@ -237,12 +247,7 @@ val perm(val seq, val k) if (null_or_missing_p(k)) { k = nil; } else { - if (!integerp(k)) - type_mismatch(lit("perm: ~s is not an integer"), k, nao); - - if (minusp(k)) - uw_throwf(numeric_error_s, lit("perm: ~s is not a positive integer"), - k, nao); + check_k(k, lit("perm")); } switch (type(seq)) { @@ -353,12 +358,7 @@ static val rperm_seq(val seq, val k) val rperm(val seq, val k) { - if (!integerp(k)) - type_mismatch(lit("rperm: ~s is not an integer"), k, nao); - - if (minusp(k)) - uw_throwf(numeric_error_s, lit("rperm: ~s is not a positive integer"), - k, nao); + check_k(k, lit("rperm")); switch (type(seq)) { case NIL: @@ -543,12 +543,7 @@ static val comb_seq(val seq, val k) val comb(val seq, val k) { - if (!integerp(k)) - type_mismatch(lit("comb: ~s is not an integer"), k, nao); - - if (minusp(k)) - uw_throwf(numeric_error_s, lit("comb: ~s is not a positive integer"), - k, nao); + check_k(k, lit("comb")); switch (type(seq)) { case CONS: @@ -690,12 +685,7 @@ static val rcomb_seq(val seq, val k) val rcomb(val seq, val k) { - if (!integerp(k)) - type_mismatch(lit("rcomb: ~s is not an integer"), k, nao); - - if (minusp(k)) - uw_throwf(numeric_error_s, lit("rcomb: ~s is not a positive integer"), - k, nao); + check_k(k, lit("rcomb")); switch (type(seq)) { case CONS: |