From: David Kastrup <dak@gnu.org>
Date: Mon, 7 Mar 2016 17:41:36 +0000 (+0100)
Subject: Create nested_property function
X-Git-Tag: release/2.19.39-1~5^2~23
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ec7f5aca60d3df0c22a51bd0c5b0274e0e5994f3;p=lilypond.git

Create nested_property function
---

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)
 {