diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index d2b89ee3..58343f1b 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -159,6 +159,7 @@ object memberp(void *data, object x, list l); object memqp(void *data, object x, list l); list assq(void *data, object x, list l); list assoc(void *data, object x, list l); +list assoc_cdr(void *data, object x, list l); /**@}*/ /** diff --git a/runtime.c b/runtime.c index c037be3b..826775b3 100644 --- a/runtime.c +++ b/runtime.c @@ -1174,6 +1174,22 @@ list assoc(void *data, object x, list l) } return boolean_f; } + +/** + * Same as assoc but check the cdr of each item for equality + */ +list assoc_cdr(void *data, object x, list l) +{ + if ((l == NULL) || is_value_type(l) || type_of(l) != pair_tag) + return boolean_f; + for (; (l != NULL); l = cdr(l)) { + list la = car(l); + Cyc_check_pair(data, la); + if (boolean_f != equalp(x, cdr(la))) + return la; + } + return boolean_f; +} /* END member and assoc */ // Internal function, do not use this anywhere outside the runtime