summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-06 01:12:00 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-06 01:12:00 -0800
commit7c2620a23a37fde4ef890acb444c4fbadf77dd33 (patch)
tree329dc419df7a98f2632a2ccd89a7b9736a253d24 /lib.c
parent6a63a6b32065f6a5839571b378605f875f9c5240 (diff)
downloadtxr-7c2620a23a37fde4ef890acb444c4fbadf77dd33.tar.gz
txr-7c2620a23a37fde4ef890acb444c4fbadf77dd33.tar.bz2
txr-7c2620a23a37fde4ef890acb444c4fbadf77dd33.zip
* hash.c (hash_grow, make_hash, make_similar_hash, copy_hash):
Pass second argument to vector. * lib.c (vector): Takes additional argument specifying the value for the slots of the vector. (vector_list, sub_vec): Pass second argument to vector. * lib.h (vector): Declaration updated. * eval.c (eval_init): Register vector as two-argument function with one required arg. * txr.1: Updated.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib.c b/lib.c
index 6798cb4f..74c712b3 100644
--- a/lib.c
+++ b/lib.c
@@ -3835,12 +3835,13 @@ val iffi(val condfun, val thenfun, val elsefun)
return func_f0v(cons(condfun, cons(thenfun, elsefun)), do_iff);
}
-val vector(val length)
+val vector(val length, val initval)
{
int i;
cnum alloc_plus = c_num(length) + 2;
val vec = make_obj();
val *v = (val *) chk_malloc(alloc_plus * sizeof *v);
+ initval = default_bool_arg(initval);
#if HAVE_VALGRIND
vec->v.vec_true_start = v;
#endif
@@ -3850,7 +3851,7 @@ val vector(val length)
v[vec_alloc] = length;
v[vec_length] = length;
for (i = 0; i < alloc_plus - 2; i++)
- vec->v.vec[i] = nil;
+ vec->v.vec[i] = initval;
return vec;
}
@@ -3937,7 +3938,7 @@ val size_vec(val vec)
val vector_list(val list)
{
- val vec = vector(zero);
+ val vec = vector(zero, nil);
if (!listp(list))
uw_throwf(error_s, lit("vector-list: list expected, not ~s"), list, nao);
@@ -4004,7 +4005,7 @@ val sub_vec(val vec_in, val from, val to)
to = max2(zero, min2(to, len));
if (ge(from, to)) {
- return vector(zero);
+ return vector(zero, nil);
} else {
cnum cfrom = c_num(from);
size_t nelem = c_num(to) - cfrom;