summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-27 07:52:02 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-27 07:52:02 -0800
commit73bcd69a66e50e08bace63cc2392803fd991f6f0 (patch)
tree29382e5ac47bddfe93d2b49e84d90c5d0fc27965
parent66858a6c861796b58b51cdc1f0a125621ec1b376 (diff)
downloadtxr-73bcd69a66e50e08bace63cc2392803fd991f6f0.tar.gz
txr-73bcd69a66e50e08bace63cc2392803fd991f6f0.tar.bz2
txr-73bcd69a66e50e08bace63cc2392803fd991f6f0.zip
* 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.
-rw-r--r--ChangeLog10
-rw-r--r--eval.c2
-rw-r--r--lib.c18
-rw-r--r--lib.h1
-rw-r--r--txr.128
5 files changed, 57 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 80739b7a..f2df059a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
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 <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