diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-01-24 10:44:10 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-01-24 10:44:10 -0800 |
commit | 19fb18a343d88621ebab989539a3463b1ffbba7d (patch) | |
tree | bde4ced4fea3ab7b347a0176dc9f5a46ace7b49b | |
parent | 71bd153f6efd3cc3157bb9dbdf55c97b6e0ad2f5 (diff) | |
download | txr-19fb18a343d88621ebab989539a3463b1ffbba7d.tar.gz txr-19fb18a343d88621ebab989539a3463b1ffbba7d.tar.bz2 txr-19fb18a343d88621ebab989539a3463b1ffbba7d.zip |
New memp function for searching a plist.
* eval.c (eval_init): Register memp intrinsic.
* lib.c (memp): New function.
* lib.h (memp): Declared.
* txr.1: Documented.
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 9 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 48 |
4 files changed, 54 insertions, 5 deletions
@@ -5800,6 +5800,7 @@ void eval_init(void) reg_fun(intern(lit("copy-cons"), user_package), func_n1(copy_cons)); reg_fun(intern(lit("copy-alist"), user_package), func_n1(copy_alist)); reg_fun(intern(lit("prop"), user_package), func_n2(getplist)); + reg_fun(intern(lit("memp"), user_package), func_n2(memp)); reg_fun(intern(lit("merge"), user_package), func_n4o(merge_wrap, 2)); reg_fun(intern(lit("sort"), user_package), func_n3o(sort, 1)); reg_fun(intern(lit("shuffle"), user_package), func_n1(shuffle)); @@ -2855,6 +2855,15 @@ val getplist_f(val list, val key, loc found) return nil; } +val memp(val key, val plist) +{ + for (; plist; plist = cddr(plist)) { + if (car(plist) == key) + return plist; + } + return nil; +} + val proper_plist_to_alist(val list) { list_collect_decl (out, ptail); @@ -611,6 +611,7 @@ val proper_list_p(val obj); val length_list(val list); val getplist(val list, val key); val getplist_f(val list, val key, loc found); +val memp(val key, val plist); val proper_plist_to_alist(val list); val improper_plist_to_alist(val list, val boolean_keys); val num(cnum val); @@ -18184,16 +18184,16 @@ function applied to the corresponding element of the input list. .SS* Property Lists -.coNP Function @ prop -.synb -.mets (prop < plist << key ) -.syne -.desc A property list a flat list of even length consisting of interleaved pairs of property names (usually symbols) and their values (arbitrary objects). An example property list is (:a 1 :b "two") which contains two properties, :a having value 1, and :b having value "two". +.coNP Function @ prop +.synb +.mets (prop < plist << key ) +.syne +.desc The .code prop function searches property list @@ -18211,6 +18211,44 @@ found, or due to the property being present with a .code nil value. +The indicators in +.meta plist +are compared with +.meta key +using +.code eq +equality, allowing them to be symbols, characters or +.code fixnum +integers. + +.coNP Function @ memp +.synb +.mets (memp < key << plist ) +.syne +.desc +The +.code memp +function searches property list +.meta plist +for key +.metn key , +using +.code eq +equality. + +If the key is found, then the entire suffix of +.meta plist +beginning with the indicator is returned, such that the first +element of the returned list is +.meta key +and the second element is the property value. + +Note the reversed argument convention relative to the +.code prop +function, harmonizing with functions in the +.code member +family. + .SS* List Sorting Note: these functions operate on lists. The principal sorting function |