+LY_DEFINE (ly_context_def_lookup, "ly:context-def-lookup",
+ 2, 1, 0, (SCM def, SCM sym, SCM val),
+ "Return the value of @var{sym} in context definition @var{def}"
+ " (e.g., @code{\\Voice}). If no value is found, return"
+ " @var{val} or @code{'()} if @var{val} is undefined."
+ " @var{sym} can be any of @samp{default-child}, @samp{consists},"
+ " @samp{description}, @samp{aliases}, @samp{accepts},"
+ " @samp{property-ops}, @samp{context-name}, @samp{group-type}.")
+{
+ LY_ASSERT_SMOB (Context_def, def, 1);
+ Context_def *cd = unsmob<Context_def> (def);
+ LY_ASSERT_TYPE (ly_is_symbol, sym, 2);
+
+ SCM res = cd->lookup (sym);
+
+ scm_remember_upto_here_1 (def);
+
+ if (SCM_UNBNDP (res))
+ res = SCM_EOL;
+
+ if (scm_is_null (res) && !SCM_UNBNDP (val))
+ return val;
+
+ return res;
+}
+
+LY_DEFINE (ly_context_def_modify, "ly:context-def-modify",
+ 2, 0, 0, (SCM def, SCM mod),
+ "Return the result of applying the context-mod @var{mod} to"
+ " the context definition @var{def}. Does not change @var{def}.")
+{
+ LY_ASSERT_SMOB (Context_def, def, 1);
+ LY_ASSERT_SMOB (Context_mod, mod, 2);
+
+ Context_def *cd = unsmob<Context_def> (def)->clone ();
+
+ for (SCM s = unsmob<Context_mod> (mod)->get_mods ();
+ scm_is_pair (s);
+ s = scm_cdr (s))
+ cd->add_context_mod (scm_car (s));
+
+ return cd->unprotect ();
+}