diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-03-23 18:39:48 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-03-23 18:39:48 -0700 |
commit | bd29917321fe68df0df4e287b06ac3ac33761114 (patch) | |
tree | ef2a1fe7aa3b537e75a8c5d9d77970e42bf25ca7 | |
parent | 9ec101dc65dd7676b5544b752c1af879d011a376 (diff) | |
download | txr-bd29917321fe68df0df4e287b06ac3ac33761114.tar.gz txr-bd29917321fe68df0df4e287b06ac3ac33761114.tar.bz2 txr-bd29917321fe68df0df4e287b06ac3ac33761114.zip |
* eval.c (eval_init): Register last function as intrinsic.
* lib.c (last): New function.
* lib.h (last): Declared.
* txr.1: Documented last.
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 6 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 16 |
5 files changed, 34 insertions, 0 deletions
@@ -1,5 +1,15 @@ 2014-03-23 Kaz Kylheku <kaz@kylheku.com> + * eval.c (eval_init): Register last function as intrinsic. + + * lib.c (last): New function. + + * lib.h (last): Declared. + + * txr.1: Documented last. + +2014-03-23 Kaz Kylheku <kaz@kylheku.com> + * eval.c (eval_init): Register empty as intrinsic. * lib.c (copy): Bugfix: handle lazy strings. Also, handle hash @@ -3257,6 +3257,7 @@ void eval_init(void) reg_fun(intern(lit("nreverse"), user_package), func_n1(nreverse)); reg_fun(intern(lit("reverse"), user_package), func_n1(reverse)); reg_fun(intern(lit("ldiff"), user_package), func_n2(ldiff)); + reg_fun(intern(lit("last"), user_package), func_n1(last)); reg_fun(intern(lit("flatten"), user_package), func_n1(flatten)); reg_fun(intern(lit("flatten*"), user_package), func_n1(lazy_flatten)); reg_fun(intern(lit("memq"), user_package), func_n2(memq)); @@ -412,6 +412,12 @@ val *lastcons(val list) return ret; } +val last(val list) +{ + val *p = lastcons(list); + return p ? *p : list; +} + val *ltail(val *cons) { while (cdr(*cons)) @@ -392,6 +392,7 @@ val listref(val list, val ind); val *listref_l(val list, val ind); val *tail(val cons); val *lastcons(val list); +val last(val list); val *ltail(val *cons); val pop(val *plist); val upop(val *plist, val *pundo); @@ -7353,6 +7353,22 @@ Examples: (ldiff a b)) -> (1) +.SS Function last + +.TP +Syntax: + + (last <list>) + +.TP +Description: + +If <list> is a nonempty proper or improper list, the last function +returns the last cons cell in the list: that cons cell whose cdr field +is a terminating atom. + +If <list> is nil, then nil is returned. + .SS Functions flatten, flatten* .TP |