From 5d9e217bb248015823c948010c1f0b47efe2cdb4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 31 Oct 2016 21:38:18 -0700 Subject: Use obj_print_impl for printing hash contents. * hash.c (print_key_val): Static function removed. (hash_print_op): Don't use maphash over print_key_val to print hash tables. Use open-coded iteration and printing with calls to obj_print_impl. This was occassioned by a bug in circle printing. The use of obj_print by hash_print_op resembles the actions of a custom print method on a structure. A bug showed up which is masked by refactoring to more direct recursion via obj_print_impl. (The bug still has to be fixed, though). --- hash.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/hash.c b/hash.c index ab2a0fd9..b2bbe0ec 100644 --- a/hash.c +++ b/hash.c @@ -248,17 +248,6 @@ cnum cobj_hash_op(val obj, int *count) abort(); } -static val print_key_val(val out, val key, val value) -{ - width_check(out, chr(' ')); - - if (value) - format(out, lit("(~s ~s)"), key, value, nao); - else - format(out, lit("(~s)"), key, nao); - return nil; -} - static val hash_equal_op(val left, val right) { uses_or2; @@ -418,7 +407,24 @@ static void hash_print_op(val hash, val out, val pretty, struct strm_ctx *ctx) obj_print_impl(h->userdata, out, pretty, ctx); } put_string(lit(")"), out); - maphash(curry_123_23(func_n3(print_key_val), out), hash); + { + val iter = hash_begin(hash), cell; + while ((cell = hash_next(iter))) { + val key = car(cell); + val value = cdr(cell); + width_check(out, chr(' ')); + + put_string(lit("("), out); + obj_print_impl(key, out, pretty, ctx); + + if (value) { + put_string(lit(" "), out); + obj_print_impl(value, out, pretty, ctx); + } + + put_string(lit(")"), out); + } + } put_string(lit(")"), out); set_indent_mode(out, save_mode); -- cgit v1.2.3