summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--ChangeLog16
-rw-r--r--eval.c2
-rw-r--r--hash.c8
-rw-r--r--lib.c9
-rw-r--r--lib.h2
-rw-r--r--txr.15
6 files changed, 30 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 859da73e..ea1aab3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2014-02-06 Kaz Kylheku <kaz@kylheku.com>
+ * 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.
+
+2014-02-06 Kaz Kylheku <kaz@kylheku.com>
+
* eval.c (op_dwim): Gutted down to just a few lines.
Basically the dwim operator is just a Lisp-1 version of the call
operator now. It doesn't have to do anything funny with non-function
diff --git a/eval.c b/eval.c
index c469adf4..613463c1 100644
--- a/eval.c
+++ b/eval.c
@@ -2655,7 +2655,7 @@ void eval_init(void)
reg_fun(intern(lit("length-str-<"), user_package), func_n2(length_str_lt));
reg_fun(intern(lit("length-str-<="), user_package), func_n2(length_str_le));
- reg_fun(intern(lit("vector"), user_package), func_n1(vector));
+ reg_fun(intern(lit("vector"), user_package), func_n2o(vector, 1));
reg_fun(intern(lit("vec"), user_package), func_n0v(vector_list));
reg_fun(intern(lit("vectorp"), user_package), func_n1(vectorp));
reg_fun(intern(lit("vec-set-length"), user_package), func_n2(vec_set_length));
diff --git a/hash.c b/hash.c
index 59665784..8ce4e4bb 100644
--- a/hash.c
+++ b/hash.c
@@ -328,7 +328,7 @@ static void hash_grow(struct hash *h)
{
cnum i;
cnum new_modulus = 2 * h->modulus;
- val new_table = vector(num_fast(new_modulus));
+ val new_table = vector(num_fast(new_modulus), nil);
bug_unless (new_modulus > h->modulus);
@@ -361,7 +361,7 @@ val make_hash(val weak_keys, val weak_vals, val equal_based)
int flags = ((weak_vals != nil) << 1) | (weak_keys != nil);
struct hash *h = (struct hash *) chk_malloc(sizeof *h);
val mod = num_fast(256);
- val table = vector(mod);
+ val table = vector(mod, nil);
val hash = cobj((mem_t *) h, hash_s, &hash_ops);
h->flags = (hash_flags_t) flags;
@@ -383,7 +383,7 @@ val make_similar_hash(val existing)
struct hash *ex = (struct hash *) cobj_handle(existing, hash_s);
struct hash *h = (struct hash *) chk_malloc(sizeof *h);
val mod = num_fast(256);
- val table = vector(mod);
+ val table = vector(mod, nil);
val hash = cobj((mem_t *) h, hash_s, &hash_ops);
h->modulus = c_num(mod);
@@ -409,7 +409,7 @@ val copy_hash(val existing)
h->modulus = ex->modulus;
h->count = ex->count;
- h->table = vector(mod);
+ h->table = vector(mod, nil);
h->userdata = ex->userdata;
h->flags = ex->flags;
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;
diff --git a/lib.h b/lib.h
index 00fb35e5..43a31740 100644
--- a/lib.h
+++ b/lib.h
@@ -630,7 +630,7 @@ val orv(val funlist);
val iff(val condfun, val thenfun, val elsefun);
val iffi(val condfun, val thenfun, val elsefun);
val swap_12_21(val fun);
-val vector(val length);
+val vector(val length, val initval);
val vectorp(val vec);
val vec_set_length(val vec, val fill);
val vecref(val vec, val ind);
diff --git a/txr.1 b/txr.1
index d7bdfd0d..734c333e 100644
--- a/txr.1
+++ b/txr.1
@@ -8775,13 +8775,14 @@ collation orders.
.TP
Syntax:
- (vector <length>)
+ (vector <length> [<initval>])
.TP
Description:
The vector function creates and returns a vector object of the specified
-length. The elements of the vector are initialized to nil.
+length. The elements of the vector are initialized to <initval>,
+or to nil if <initval> is omitted.
.SS Function vec