diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-08-07 13:09:42 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-08-07 13:09:42 -0700 |
commit | bde7b8dfe688ce05f445b5ed18f22d6b2a526c3a (patch) | |
tree | 51cdb9bd8ab7673dda15cbcbc5ac65be59ceb478 | |
parent | 1a18561313f4a66e5e454b48c08be160d9fe6c18 (diff) | |
download | txr-bde7b8dfe688ce05f445b5ed18f22d6b2a526c3a.tar.gz txr-bde7b8dfe688ce05f445b5ed18f22d6b2a526c3a.tar.bz2 txr-bde7b8dfe688ce05f445b5ed18f22d6b2a526c3a.zip |
New spl and tok: variants of tok-str and split-str.
* eval.c (eval_init): Register spl and tok intrinsics.
* lib.c (spl, tok): New functions.
* txr.1: Documented.
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | lib.c | 14 | ||||
-rw-r--r-- | lib.h | 2 | ||||
-rw-r--r-- | txr.1 | 68 |
4 files changed, 86 insertions, 0 deletions
@@ -6032,8 +6032,10 @@ void eval_init(void) reg_fun(intern(lit("replace-str"), user_package), func_n4o(replace_str, 2)); reg_fun(intern(lit("cat-str"), user_package), func_n2o(cat_str, 1)); reg_fun(intern(lit("split-str"), user_package), func_n3o(split_str_keep, 2)); + reg_fun(intern(lit("spl"), user_package), func_n3o(spl, 2)); reg_fun(intern(lit("split-str-set"), user_package), func_n2(split_str_set)); reg_fun(intern(lit("tok-str"), user_package), func_n3o(tok_str, 2)); + reg_fun(intern(lit("tok"), user_package), func_n3o(tok, 2)); reg_fun(intern(lit("tok-where"), user_package), func_n2(tok_where)); reg_fun(intern(lit("list-str"), user_package), func_n1(list_str)); reg_fun(intern(lit("trim-str"), user_package), func_n1(trim_str)); @@ -4202,6 +4202,13 @@ val split_str_keep(val str, val sep, val keep_sep) } } +val spl(val sep, val arg1, val arg2) +{ + return if3(missingp(arg2), + split_str_keep(arg1, sep, arg2), + split_str_keep(arg2, sep, arg1)); +} + val split_str(val str, val sep) { return split_str_keep(str, sep, nil); @@ -4287,6 +4294,13 @@ val tok_str(val str, val tok_regex, val keep_sep) return out; } +val tok(val tok_regex, val arg1, val arg2) +{ + return if3(missingp(arg2), + tok_str(arg1, tok_regex, arg2), + tok_str(arg2, tok_regex, arg1)); +} + val tok_where(val str, val tok_regex) { list_collect_decl (out, iter); @@ -769,8 +769,10 @@ val cat_str(val list, val sep); val scat(val sep, ...); val split_str(val str, val sep); val split_str_keep(val str, val sep, val keep_sep); +val spl(val sep, val arg1, val arg2); val split_str_set(val str, val set); val tok_str(val str, val tok_regex, val keep_sep); +val tok(val tok_regex, val arg1, val arg2); val tok_where(val str, val tok_regex); val list_str(val str); val trim_str(val str); @@ -21172,6 +21172,40 @@ last character, whereas does not recognize empty separators at these outer limits of the string. +.coNP Function @ spl +.synb +.mets (spl < sep <> [ keep-between ] << string ) +.syne +.desc +The +.code spl +function performs the same computation as +.codn split-str . +The same-named parameters of +.code spl +and +.code split-str +have the same semantics. The difference is the argument order. +The +.code spl +function takes the +.meta sep +argument first. +The last argument is always +.meta string +whether or not there are two arguments or three. If there are +three arguments, then +.meta keep-between +is the middle one. + +Note: the argument conventions of +.code spl +facilitate less verbose partial application, such as with macros in the +.code op +family, in the common situation when +.meta string +is the unbound argument. + .coNP Function @ split-str-set .synb .mets (split-str-set < string << set ) @@ -21303,6 +21337,40 @@ The tok-where function does not support the .meta keep-between parameter. +.coNP Function @ tok +.synb +.mets (tok-str < regex <> [ keep-between ] << string ) +.syne +.desc +The +.code tok +function performs the same computation as +.codn tok-str . +The same-named parameters of +.code tok +and +.code tok-str +have the same semantics. The difference is the argument order. +The +.code tok +function takes the +.meta regex +argument first. +The last argument is always +.meta string +whether or not there are two arguments or three. If there are +three arguments, then +.meta keep-between +is the middle one. + +Note: the argument conventions of +.code tok +facilitate less verbose partial application, such as with macros in the +.code op +family, in the common situation when +.meta string +is the unbound argument. + .coNP Function @ list-str .synb .mets (list-str << string ) |