diff options
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | hash.c | 8 | ||||
-rw-r--r-- | lib.c | 9 | ||||
-rw-r--r-- | lib.h | 2 | ||||
-rw-r--r-- | txr.1 | 5 |
6 files changed, 30 insertions, 12 deletions
@@ -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 @@ -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)); @@ -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; @@ -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; @@ -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); @@ -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 |