From ec7f5aca60d3df0c22a51bd0c5b0274e0e5994f3 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Mon, 7 Mar 2016 18:41:36 +0100 Subject: [PATCH] Create nested_property function --- lily/include/context.hh | 1 + lily/nested-property.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lily/include/context.hh b/lily/include/context.hh index c4af7bce05..ab89593d1b 100644 --- a/lily/include/context.hh +++ b/lily/include/context.hh @@ -193,6 +193,7 @@ void set_context_property_on_children (Context *trans, SCM sym, SCM val); } while (0) SCM nested_property_alist (SCM alist, SCM prop_path, SCM value); +SCM nested_property (SCM alist, SCM prop_path, SCM fallback = SCM_EOL); SCM nested_create_alist (SCM prop_path, SCM value); SCM partial_list_copy (SCM alist, SCM tail, SCM newtail); SCM assq_tail (SCM key, SCM alist, SCM alist_end); diff --git a/lily/nested-property.cc b/lily/nested-property.cc index 7c8b13047d..27adf55dbe 100644 --- a/lily/nested-property.cc +++ b/lily/nested-property.cc @@ -131,6 +131,19 @@ nested_property_alist (SCM alist, SCM prop_path, SCM value) return scm_acons (key, value, alist); } +SCM +nested_property (SCM alist, SCM prop_path, SCM fallback) +{ + for (; scm_is_pair (prop_path); prop_path = scm_cdr (prop_path)) + { + SCM tail = assoc_tail (scm_car (prop_path), alist); + if (scm_is_false (tail)) + return fallback; + alist = scm_cdar (tail); + } + return alist; +} + void set_nested_property (Grob *me, SCM big_to_small, SCM value) { -- 2.39.2