summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index d20d7b20..672efa4a 100644
--- a/lib.c
+++ b/lib.c
@@ -719,7 +719,7 @@ val proper_listp(val obj)
return (obj == nil) ? t : nil;
}
-val length(val list)
+val length_list(val list)
{
cnum len = 0;
while (consp(list)) {
@@ -2310,6 +2310,31 @@ val vec_push(val vec, val item)
return fill;
}
+val length_vec(val vec)
+{
+ type_check(vec, VEC);
+ return vec->v.vec[vec_fill];
+}
+
+val size_vec(val vec)
+{
+ type_check(vec, VEC);
+ return vec->v.vec[vec_alloc];
+}
+
+val vector_list(val list)
+{
+ val vec = vector(num(2));
+
+ if (!listp(list))
+ uw_throwf(error_s, lit("vector_list: list expected, not ~s"), list, nao);
+
+ for (; consp(list); list = cdr(list))
+ vec_push(vec, car(list));
+
+ return vec;
+}
+
static val lazy_stream_func(val env, val lcons)
{
val stream = car(env);
@@ -2854,6 +2879,24 @@ val set_diff(val list1, val list2, val testfun, val keyfun)
return out;
}
+val length(val seq)
+{
+ if (seq == nil)
+ return num(0);
+ else switch (type(seq)) {
+ case CONS:
+ case LCONS:
+ return length_list(seq);
+ case LIT:
+ case STR:
+ return length_str(seq);
+ case VEC:
+ return length_vec(seq);
+ default:
+ type_mismatch(lit("~s is not a sequence"), cons, nao);
+ }
+}
+
val env(void)
{
if (env_list) {