use of org.matheclipse.core.visit.VisitorLevelSpecification in project symja_android_library by axkr.
the class MapAll method evaluate.
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
Validate.checkRange(ast, 3);
final IAST arg1AST = F.ast(ast.arg1());
final VisitorLevelSpecification level = new VisitorLevelSpecification(Functors.append(arg1AST), 0, Integer.MAX_VALUE, false);
final IExpr result = ast.arg2().accept(level);
return result.isPresent() ? result : ast.arg2();
}
use of org.matheclipse.core.visit.VisitorLevelSpecification in project symja_android_library by axkr.
the class Replace method replaceExprWithLevelSpecification.
private static IExpr replaceExprWithLevelSpecification(final IAST ast, IExpr arg1, IExpr rules, IExpr exprLevelSpecification, EvalEngine engine) {
// use replaceFunction#setRule() method to set the current rules which
// are initialized with null
ReplaceFunction replaceFunction = new ReplaceFunction(ast, null, engine);
VisitorLevelSpecification level = new VisitorLevelSpecification(replaceFunction, exprLevelSpecification, false);
if (rules.isListOfLists()) {
IAST result = F.List();
for (IExpr list : (IAST) rules) {
IExpr temp = F.NIL;
IAST subList = (IAST) list;
for (IExpr element : subList) {
if (element.isRuleAST()) {
IAST rule = (IAST) element;
replaceFunction.setRule(rule);
temp = arg1.accept(level);
if (temp.isPresent()) {
break;
}
} else {
WrongArgumentType wat = new WrongArgumentType(ast, ast, -1, "Rule expression (x->y) expected: ");
throw wat;
}
}
result.append(temp.orElse(arg1));
}
return result;
}
replaceFunction.setRule(rules);
return arg1.accept(level).orElse(arg1);
}
Aggregations