]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/nested-property.cc
Add assv_tail function
[lilypond.git] / lily / nested-property.cc
index 7c8b13047d726e8f8d45fc2e44300402e038d31a..d45f395b304388dba633411a53c339b2005a9e3f 100644 (file)
@@ -37,6 +37,17 @@ assq_tail (SCM key, SCM alist, SCM based_on = SCM_EOL)
   return SCM_BOOL_F;
 }
 
+SCM
+assv_tail (SCM key, SCM alist, SCM based_on = SCM_EOL)
+{
+  for (SCM p = alist; !scm_is_eq (p, based_on); p = scm_cdr (p))
+    {
+      if (scm_is_true (scm_eqv_p (scm_caar (p), key)))
+        return p;
+    }
+  return SCM_BOOL_F;
+}
+
 SCM
 assoc_tail (SCM key, SCM alist, SCM based_on = SCM_EOL)
 {
@@ -131,6 +142,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)
 {