]> git.donarmstrong.com Git - lilypond.git/commitdiff
Create nested_property function
authorDavid Kastrup <dak@gnu.org>
Mon, 7 Mar 2016 17:41:36 +0000 (18:41 +0100)
committerDavid Kastrup <dak@gnu.org>
Sat, 19 Mar 2016 13:20:03 +0000 (14:20 +0100)
lily/include/context.hh
lily/nested-property.cc

index c4af7bce0579255dea4919f034065a00b3640bf8..ab89593d1bbad317b38de9e5b58a865224bc085b 100644 (file)
@@ -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);
index 7c8b13047d726e8f8d45fc2e44300402e038d31a..27adf55dbe27a22885196944188dc6bc39b88959 100644 (file)
@@ -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)
 {