feat(kernel/expr): add get_app_args_at_most

This commit is contained in:
Leonardo de Moura 2016-01-06 17:29:28 -08:00
parent 9a1a9f3b5a
commit 930fcddace
2 changed files with 25 additions and 0 deletions

View file

@ -447,6 +447,21 @@ expr const & get_app_args(expr const & e, buffer<expr> & args) {
return *it;
}
expr const & get_app_args_at_most(expr const & e, unsigned num, buffer<expr> & args) {
unsigned sz = args.size();
expr const * it = &e;
unsigned i = 0;
while (is_app(*it)) {
if (i == num)
break;
args.push_back(app_arg(*it));
it = &(app_fn(*it));
i++;
}
std::reverse(args.begin() + sz, args.end());
return *it;
}
expr const & get_app_rev_args(expr const & e, buffer<expr> & args) {
expr const * it = &e;
while (is_app(*it)) {

View file

@ -567,6 +567,16 @@ inline bool closed(expr const & e) { return !has_free_vars(e); }
It returns the f.
*/
expr const & get_app_args(expr const & e, buffer<expr> & args);
/** \brief Similar to \c get_app_args, but stores at most num args.
Examples:
1) get_app_args_at_most(f a b c, 2, args);
stores {b, c} in args and returns (f a)
2) get_app_args_at_most(f a b c, 4, args);
stores {a, b, c} in args and returns f
*/
expr const & get_app_args_at_most(expr const & e, unsigned num, buffer<expr> & args);
/**
\brief Similar to \c get_app_args, but arguments are stored in reverse order in \c args.
If e is of the form <tt>(...(f a1) ... an)</tt>, then the procedure stores [an, ..., a1] in \c args.