summaryrefslogtreecommitdiffstats
path: root/tree.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-10-16 07:50:36 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-10-16 07:50:36 -0700
commit8c907a932436a8bdc2c52d2a28e14115df525654 (patch)
treee7260805bbff9835999340820255ac98ae64686f /tree.c
parentbdc7277d09377f87319e0c27de40210b0212fabc (diff)
downloadtxr-8c907a932436a8bdc2c52d2a28e14115df525654.tar.gz
txr-8c907a932436a8bdc2c52d2a28e14115df525654.tar.bz2
txr-8c907a932436a8bdc2c52d2a28e14115df525654.zip
tree: printing: handle unnamed functions.
* tree.c (tree): If the tree abstraction functions don't have a name, then use the functions themselves as the names, rather than nil. Otherwise the printed representation of the tree will look like it has the default abstraction functions.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/tree.c b/tree.c
index 11cc612e..b6a20829 100644
--- a/tree.c
+++ b/tree.c
@@ -596,14 +596,18 @@ val tree(val keys_in, val key_fn, val less_fn, val equal_fn)
val keys = default_null_arg(keys_in), key;
val tree = cobj(coerce(mem_t *, tr), tree_s, &tree_ops);
seq_iter_t ki;
+ uses_or2;
tr->key_fn = default_null_arg(key_fn);
tr->less_fn = default_null_arg(less_fn);
tr->equal_fn = default_null_arg(equal_fn);
- tr->key_fn_name = if2(tr->key_fn, func_get_name(tr->key_fn, nil));
- tr->less_fn_name = if2(tr->less_fn, func_get_name(tr->less_fn, nil));
- tr->equal_fn_name = if2(tr->equal_fn, func_get_name(tr->equal_fn, nil));
+ tr->key_fn_name = if2(tr->key_fn,
+ or2(func_get_name(tr->key_fn, nil), tr->key_fn));
+ tr->less_fn_name = if2(tr->less_fn,
+ or2(func_get_name(tr->less_fn, nil), tr->key_fn));
+ tr->equal_fn_name = if2(tr->equal_fn,
+ or2(func_get_name(tr->equal_fn, nil), tr->key_fn));
seq_iter_init(tree_s, &ki, keys);