From 1ca65fef46ca68ca18e3db5a5eac316d5cf25799 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 10 Dec 2016 20:06:38 -0800 Subject: New function: endp. This improves compatibility with other Lisp dialects in a small way. * eval.c (eval_init): Register endp intrinsic. * lib.c (endp): New function. * lib.h (endp): Declared. * txr.1: Documented endp. --- eval.c | 1 + lib.c | 10 ++++++++++ lib.h | 1 + txr.1 | 25 +++++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/eval.c b/eval.c index a5888e9f..5b7065e4 100644 --- a/eval.c +++ b/eval.c @@ -5139,6 +5139,7 @@ void eval_init(void) reg_fun(intern(lit("consp"), user_package), func_n1(consp)); reg_fun(intern(lit("lconsp"), user_package), func_n1(lconsp)); reg_fun(intern(lit("listp"), user_package), func_n1(listp)); + reg_fun(intern(lit("endp"), user_package), func_n1(endp)); { val proper_list_p_f = func_n1(proper_list_p); reg_fun(intern(lit("proper-listp"), user_package), proper_list_p_f); diff --git a/lib.c b/lib.c index 1ca1790c..6576049c 100644 --- a/lib.c +++ b/lib.c @@ -2758,6 +2758,16 @@ val listp(val obj) return if2(obj == nil || consp(obj), t); } +val endp(val obj) +{ + if (obj == nil) + return t; + if (consp(obj)) + return nil; + uw_throwf(error_s, lit("endp: list improperly terminated by ~s"), + obj, nao); +} + val proper_list_p(val obj) { while (consp(obj)) diff --git a/lib.h b/lib.h index 4a4e52a4..3ebc5c22 100644 --- a/lib.h +++ b/lib.h @@ -606,6 +606,7 @@ val consp(val obj); val lconsp(val obj); val atom(val obj); val listp(val obj); +val endp(val obj); val proper_list_p(val obj); val length_list(val list); val getplist(val list, val key); diff --git a/txr.1 b/txr.1 index ca74fe48..549a7da3 100644 --- a/txr.1 +++ b/txr.1 @@ -17046,6 +17046,31 @@ installations should use .codn proper-listp , but its use going forward is deprecated. +.coNP Function @ endp +.synb +.mets (endp << object ) +.syne +.desc +The +.code endp +function returns +.code t +if +.meta object +is the object +.codn nil . + +If +.meta object +is a cons cell, then +.code endp +returns +.codn t . + +Otherwise, +.code endp +function throws an exception. + .coNP Function @ length-list .synb .mets (length-list << list ) -- cgit v1.2.3