diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | lib.c | 18 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 28 |
5 files changed, 57 insertions, 2 deletions
@@ -1,5 +1,15 @@ 2014-02-27 Kaz Kylheku <kaz@kylheku.com> + * 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 <kaz@kylheku.com> + * genvim.txr: Updated with regard to how operators are registered in in eval_init. Also, scans reg_mac registrations now. @@ -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)); @@ -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)) { @@ -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); @@ -9355,10 +9355,36 @@ produces a catenation of the vectors listed in <vec-list>. 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 <sequence>) + +.TP +Description: + +The length function returns the number of items in <sequence>, and +returns it. + +.SS Function copy + +.TP +Syntax: + + (copy <sequence>) + +.TP +Description: + +The copy function duplicates a sequence. If <sequence> is nil, it +returns nil. If <sequence> is a list, it returns (copy-list <sequence>); +if <sequence> is a string, it returns (copy-str <sequence>); and +if <sequence> is a vector, it returns (copy-vec <sequence>). + .SS Function sub .TP |