From 73bcd69a66e50e08bace63cc2392803fd991f6f0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 27 Feb 2014 07:52:02 -0800 Subject: * lib.c (copy): New function. * lib.h (copy): Declared. * eval.c (eval_init): Registered copy function as intrinsic. * txr.1: Added missing documentation for length. Documented copy. --- ChangeLog | 10 ++++++++++ eval.c | 2 +- lib.c | 18 ++++++++++++++++++ lib.h | 1 + txr.1 | 28 +++++++++++++++++++++++++++- 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80739b7a..f2df059a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2014-02-27 Kaz Kylheku + + * lib.c (copy): New function. + + * lib.h (copy): Declared. + + * eval.c (eval_init): Registered copy function as intrinsic. + + * txr.1: Added missing documentation for length. Documented copy. + 2014-02-27 Kaz Kylheku * genvim.txr: Updated with regard to how operators are registered in diff --git a/eval.c b/eval.c index a1566c4c..9cb75aa7 100644 --- a/eval.c +++ b/eval.c @@ -3483,7 +3483,7 @@ void eval_init(void) reg_fun(intern(lit("set-diff"), user_package), func_n4o(set_diff, 2)); reg_fun(intern(lit("length"), user_package), func_n1(length)); - + reg_fun(intern(lit("copy"), user_package), func_n1(copy)); reg_fun(intern(lit("sub"), user_package), func_n3o(sub, 1)); reg_fun(intern(lit("ref"), user_package), func_n2(ref)); reg_fun(intern(lit("refset"), user_package), func_n3(refset)); diff --git a/lib.c b/lib.c index 9aa3af95..da3ae5a3 100644 --- a/lib.c +++ b/lib.c @@ -4879,6 +4879,24 @@ val set_diff(val list1, val list2, val testfun, val keyfun) return make_like(out, list_orig); } +val copy(val seq) +{ + switch (type(seq)) { + case NIL: + return nil; + case CONS: + case LCONS: + return copy_list(seq); + case LIT: + case STR: + return copy_str(seq); + case VEC: + return copy_vec(seq); + default: + type_mismatch(lit("copy: ~s is not a sequence"), seq, nao); + } +} + val length(val seq) { switch (type(seq)) { diff --git a/lib.h b/lib.h index d3f251fc..d2548e09 100644 --- a/lib.h +++ b/lib.h @@ -687,6 +687,7 @@ val posq(val obj, val list); val pos(val list, val key, val testfun, val keyfun); val pos_if(val pred, val list, val key); val set_diff(val list1, val list2, val testfun, val keyfun); +val copy(val seq); val length(val seq); val sub(val seq, val from, val to); val ref(val seq, val ind); diff --git a/txr.1 b/txr.1 index 1aa82bb6..243e0c93 100644 --- a/txr.1 +++ b/txr.1 @@ -9355,10 +9355,36 @@ produces a catenation of the vectors listed in . It returns a single large vector formed by catenating those vectors together in order. -.SH GENERIC SEQUENCE OPERATIONS +.SH SEQUENCE MANIPULATION .SS Function length +.TP +Syntax: + + (length ) + +.TP +Description: + +The length function returns the number of items in , and +returns it. + +.SS Function copy + +.TP +Syntax: + + (copy ) + +.TP +Description: + +The copy function duplicates a sequence. If is nil, it +returns nil. If is a list, it returns (copy-list ); +if is a string, it returns (copy-str ); and +if is a vector, it returns (copy-vec ). + .SS Function sub .TP -- cgit v1.2.3