+/* procedure-minimum-arity support. */
+static void
+parse_arity (SCM arity, int *req, int *opt, int *rest)
+{
+ SCM x = scm_cddr (arity);
+
+ if (scm_is_pair (x))
+ {
+ *req = scm_to_int (scm_car (x));
+ x = scm_cdr (x);
+ if (scm_is_pair (x))
+ {
+ *opt = scm_to_int (scm_car (x));
+ x = scm_cdr (x);
+ if (scm_is_pair (x))
+ *rest = scm_is_true (scm_car (x));
+ else
+ *rest = 0;
+ }
+ else
+ *opt = *rest = 0;
+ }
+ else
+ *req = *opt = *rest = 0;
+}
+
+int
+scm_i_program_arity (SCM program, int *req, int *opt, int *rest)
+{
+ SCM arities;
+
+ arities = scm_program_arities (program);
+ if (!scm_is_pair (arities))
+ return 0;
+
+ parse_arity (scm_car (arities), req, opt, rest);
+ arities = scm_cdr (arities);
+
+ for (; scm_is_pair (arities); arities = scm_cdr (arities))
+ {
+ int thisreq, thisopt, thisrest;
+
+ parse_arity (scm_car (arities), &thisreq, &thisopt, &thisrest);
+
+ if (thisreq < *req
+ || (thisreq == *req
+ && ((thisrest && (!*rest || thisopt > *opt))
+ || (!thisrest && !*rest && thisopt > *opt))))
+ {
+ *req = thisreq;
+ *opt = thisopt;
+ *rest = thisrest;
+ }
+ }
+
+ return 1;
+}