From 90bb65d4b4162df4099c811e802e452cd42d1c72 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 23 Mar 2020 19:11:17 -0700 Subject: New contains function: near alias of search. Harmonizes with starts-with and ends-with. * eval.c (eval_init): Register contains intrinsic. * lib.c (contains): New function. * lib.h (contains): Delared. * txr.1: Documented. --- eval.c | 1 + lib.c | 5 +++++ lib.h | 1 + txr.1 | 17 ++++++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/eval.c b/eval.c index dd2adcf4..805805b3 100644 --- a/eval.c +++ b/eval.c @@ -6892,6 +6892,7 @@ void eval_init(void) reg_fun(intern(lit("update"), user_package), func_n2(update)); reg_fun(intern(lit("search"), user_package), func_n4o(search, 2)); reg_fun(intern(lit("rsearch"), user_package), func_n4o(rsearch, 2)); + reg_fun(intern(lit("contains"), user_package), func_n4o(contains, 2)); reg_fun(intern(lit("where"), user_package), func_n2(where)); reg_fun(intern(lit("select"), user_package), func_n2(sel)); reg_fun(intern(lit("relate"), user_package), func_n3o(relate, 2)); diff --git a/lib.c b/lib.c index 3dce3750..acf66f36 100644 --- a/lib.c +++ b/lib.c @@ -10786,6 +10786,11 @@ val search(val seq, val key, val testfun, val keyfun) } } +val contains(val key, val seq, val testfun, val keyfun) +{ + return search(seq, key, testfun, keyfun); +} + static val rsearch_list(val seq, val key, val testfun, val keyfun) { val siter, kiter; diff --git a/lib.h b/lib.h index 6c5b17ef..115b11d2 100644 --- a/lib.h +++ b/lib.h @@ -1155,6 +1155,7 @@ val butlast(val seq, val idx); val replace(val seq, val items, val from, val to); val update(val seq, val fun); val search(val seq, val key, val from, val to); +val contains(val key, val seq, val testfun, val keyfun); val rsearch(val seq, val key, val from, val to); val where(val func, val seq); val sel(val seq, val where); diff --git a/txr.1 b/txr.1 index f0b1726d..0d087525 100644 --- a/txr.1 +++ b/txr.1 @@ -29680,7 +29680,7 @@ is returned. .coNP Function @ search .synb -.mets (search < haystack < needle >> [ testfun <> [ keyfun ]) +.mets (search < haystack < needle >> [ testfun <> [ keyfun ]]) .syne .desc The @@ -29773,6 +29773,21 @@ with one argument. If it is not supplied, it defaults to [search "abcd" #(#\eC #\eD) : chr-toupper] -> 2 .brev +.coNP Function @ contains +.synb +.mets (contains < needle < haystack >> [ testfun <> [ keyfun ]]) +.syne +.desc +The syntax of the +.code contains +function differs from that of +.codn search : +that the +.meta needle +and +.meta haystack +arguments are reversed. The semantics is identical. + .coNP Function @ rsearch .synb .mets (rsearch < haystack < needle >> [ testfun <> [ keyfun ]) -- cgit v1.2.3