diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-09-03 23:29:24 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-09-03 23:29:24 -0700 |
commit | 1777ba3dc87c62cf18cd178f2055369979907dc8 (patch) | |
tree | a59a11cb6070442cc778618f1824badd55394f88 | |
parent | c98f779588624b9f5479c9740920e7760a1f7d98 (diff) | |
download | txr-1777ba3dc87c62cf18cd178f2055369979907dc8.tar.gz txr-1777ba3dc87c62cf18cd178f2055369979907dc8.tar.bz2 txr-1777ba3dc87c62cf18cd178f2055369979907dc8.zip |
New function: tailp.
* eval.c (eval_init): Register tailp intrinsic.
* lib.c (tailp): New function.
* lib.h (tailp): Declared.
* txr.1: Documented.
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 10 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 53 |
4 files changed, 65 insertions, 0 deletions
@@ -6458,6 +6458,7 @@ void eval_init(void) reg_fun(intern(lit("split"), user_package), func_n2(split)); reg_fun(intern(lit("split*"), user_package), func_n2(split_star)); reg_fun(intern(lit("partition*"), user_package), func_n2(partition_star)); + reg_fun(intern(lit("tailp"), user_package), func_n2(tailp)); reg_fun(memq_s, func_n2(memq)); reg_fun(memql_s, func_n2(memql)); reg_fun(memqual_s, func_n2(memqual)); @@ -1682,6 +1682,16 @@ val ldiff_old(val list1, val list2) return make_like(out, list_orig); } +val tailp(val obj, val list) +{ + while (obj != list) { + if (atom(list)) + return nil; + list = cdr(list); + } + return t; +} + val memq(val obj, val list) { val list_orig = list; @@ -613,6 +613,7 @@ val partition(val seq, val indices); val split(val seq, val indices); val partition_star(val seq, val indices); val split_star(val seq, val indices); +val tailp(val obj, val list); val memq(val obj, val list); val rmemq(val obj, val list); val memql(val obj, val list); @@ -19568,6 +19568,59 @@ is only a function, not an accessor; .code nthcdr forms do not denote places. +.coNP Function @ tailp +.synb +.mets (tailp < object << list) +.syne +.desc +The +.code tailp +function tests whether +.meta object +is a tail of +.metn list . +This means that +.meta object +is either +.meta list +itself, or else one of the +.code cons +cells of +.meta list +or else the terminating atom of +.metn list . + +More formally, a recursive definition follows. +If +.meta object +and +.meta list +are the same object (thus equal under the +.code eq +function) then +.code tailp +returns +.codn t . +If +.meta list +is an atom, and is not +.metn object , +then the function returns +.codn nil . +Otherwise, +.meta list +is a +.code cons +that is not +.meta object +and +.code tailp +yields the same value as the +.mono +.meti "(tailp < object (cdr << list ))" +.onom +expression. + .coNP Accessors @, caar @, cadr @, cdar @, cddr @ ... and @ cdddddr .synb .mets (caar << object ) |