diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-03-12 22:37:21 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-03-12 22:37:21 -0700 |
commit | 33e0a53bd96744a92fef7e364e7625bde57d7699 (patch) | |
tree | 1065b0c534a555cba9c96bf17bc473f552b13c11 | |
parent | 7717eedcb68dfa7cfdd2327f9c29f99e9ecc4c01 (diff) | |
download | txr-33e0a53bd96744a92fef7e364e7625bde57d7699.tar.gz txr-33e0a53bd96744a92fef7e364e7625bde57d7699.tar.bz2 txr-33e0a53bd96744a92fef7e364e7625bde57d7699.zip |
lib: introduce new make_lazy_cons variant.
* lib.c (make_lazy_cons_car_cdr): New function.
(lazy_where_func, lazy_where_hash_func, where): Use
make_lazy_cons_car and the new make_lazy_cons_car_cdr instead
of two-step construction and initialization with us_rplaca and
us_rplacd.
* lib.h (make_lazy_cons_car_cdr): Declared.
-rw-r--r-- | lib.c | 30 | ||||
-rw-r--r-- | lib.h | 1 |
2 files changed, 16 insertions, 15 deletions
@@ -3012,6 +3012,16 @@ val make_lazy_cons_car(val func, val car) return obj; } +val make_lazy_cons_car_cdr(val func, val car, val cdr) +{ + val obj = make_obj(); + obj->lc.type = LCONS; + obj->lc.car = car; + obj->lc.cdr = cdr; + obj->lc.func = func; + return obj; +} + void rcyc_cons(val cons) { cons->c.cdr = recycled_conses; @@ -10776,9 +10786,7 @@ static val lazy_where_func(val seq_iter, val lcons) } { - val cell = make_lazy_cons(lcons_fun(lcons)); - us_rplaca(cell, index); - us_rplacd(lcons, cell); + us_rplacd(lcons, make_lazy_cons_car(lcons_fun(lcons), index)); return nil; } } @@ -10801,10 +10809,7 @@ static val lazy_where_hash_func(val hash_iter, val lcons) } { - val cell = make_lazy_cons(us_lcons_fun(lcons)); - us_rplaca(cell, key); - us_rplacd(cell, func); - us_rplacd(lcons, cell); + us_rplacd(lcons, make_lazy_cons_car_cdr(us_lcons_fun(lcons), key, func)); return nil; } } @@ -10828,9 +10833,8 @@ val where(val func, val seq) } { - val cell = make_lazy_cons(func_f1(seq_iter, lazy_where_func)); + val cell = make_lazy_cons_car(func_f1(seq_iter, lazy_where_func), index); si->inf.obj = func; - us_rplaca(cell, index); return cell; } } else { @@ -10847,12 +10851,8 @@ val where(val func, val seq) } } - { - val cell = make_lazy_cons(func_f1(hash_iter, lazy_where_hash_func)); - us_rplaca(cell, key); - us_rplacd(cell, func); - return cell; - } + return make_lazy_cons_car_cdr(func_f1(hash_iter, lazy_where_hash_func), + key, func); } } @@ -664,6 +664,7 @@ mem_t *chk_xalloc(ucnum m, ucnum n, val self); val cons(val car, val cdr); val make_lazy_cons(val func); val make_lazy_cons_car(val func, val car); +val make_lazy_cons_car_cdr(val func, val car, val cdr); void rcyc_cons(val cons); void rcyc_list(val list); void rcyc_empty(void); |