summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-02-19 01:07:31 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-02-19 01:07:31 -0800
commitd41a04ccef6e3a511582bd0e25721649d476b2d4 (patch)
tree81e18fc8bf8748b537acd4f1680027543380fab8 /lib.c
parent056107ff44d2ae75b7b7db98979d1a920a37d439 (diff)
downloadtxr-d41a04ccef6e3a511582bd0e25721649d476b2d4.tar.gz
txr-d41a04ccef6e3a511582bd0e25721649d476b2d4.tar.bz2
txr-d41a04ccef6e3a511582bd0e25721649d476b2d4.zip
* lib.c (sub, ref, replace): New functions.
* lib.h (sub, ref, replace): Declared. * match.c (format_field): Generic indexing using new functions. * txr.1: Documentation stub. * txr.vim: Highlighting for new functions.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 94cb19d3..fe433d3a 100644
--- a/lib.c
+++ b/lib.c
@@ -3570,7 +3570,62 @@ val length(val seq)
case VEC:
return length_vec(seq);
default:
- type_mismatch(lit("~s is not a sequence"), cons, nao);
+ type_mismatch(lit("length: ~s is not a sequence"), cons, nao);
+ }
+}
+
+val sub(val seq, val from, val to)
+{
+ if (seq == nil)
+ return nil;
+ else switch (type(seq)) {
+ case CONS:
+ case LCONS:
+ return sub_list(seq, from, to);
+ case LIT:
+ case STR:
+ return sub_str(seq, from, to);
+ case VEC:
+ return sub_vec(seq, from, to);
+ default:
+ type_mismatch(lit("sub: ~s is not a sequence"), cons, nao);
+ }
+}
+
+val ref(val seq, val ind)
+{
+ if (seq == nil)
+ return nil;
+ else switch (type(seq)) {
+ case CONS:
+ case LCONS:
+ return listref(seq, ind);
+ case LIT:
+ case STR:
+ return chr_str(seq, ind);
+ case VEC:
+ return vecref(seq, ind);
+ default:
+ type_mismatch(lit("ref: ~s is not a sequence"), cons, nao);
+ }
+}
+
+val replace(val seq, val from, val to, val items)
+{
+ if (seq == nil)
+ goto list;
+ switch (type(seq)) {
+ case CONS:
+ case LCONS:
+ list:
+ return replace_list(seq, from, to, items);
+ case LIT:
+ case STR:
+ return replace_str(seq, from, to, items);
+ case VEC:
+ return replace_vec(seq, from, to, items);
+ default:
+ type_mismatch(lit("replace: ~s is not a sequence"), cons, nao);
}
}