use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class ModuleReplaceAll method visitNestedScope.
/**
* Handle nested Module(), With() or Function()
*
* @param ast
* @param isFunction <code>ast</code> has the form <code>Function(a1, a2)</code>
* @return
*/
private IAST visitNestedScope(IAST ast, boolean isFunction) {
IAST localVariablesList = F.NIL;
if (ast.arg1().isSymbol()) {
localVariablesList = F.list(ast.arg1());
} else if (ast.arg1().isList()) {
localVariablesList = (IAST) ast.arg1();
}
ModuleReplaceAll visitor = this;
if (localVariablesList.isPresent()) {
IdentityHashMap<ISymbol, IExpr> variables = renamedVariables(localVariablesList, isFunction);
if (variables != null) {
visitor = new ModuleReplaceAll(variables, fEngine, moduleCounter);
}
}
IExpr temp;
int i = fOffset;
while (i < ast.size()) {
temp = ast.get(i).accept(visitor);
if (temp.isPresent()) {
// something was evaluated - return a new IAST:
IASTMutable result = ast.setAtCopy(i++, temp);
while (i < ast.size()) {
temp = ast.get(i).accept(visitor);
if (temp.isPresent()) {
result.set(i, temp);
}
i++;
}
return result;
}
i++;
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class ModuleReplaceAll method visitASTModule.
private IExpr visitASTModule(IAST ast) {
IExpr temp;
int i = fOffset;
final int size = ast.size();
while (i < size) {
temp = ast.get(i).accept(this);
if (temp.isPresent()) {
// something was evaluated - return a new IAST:
IASTMutable result = ast.setAtCopy(i++, temp);
ast.forEach(i, size, (x, j) -> {
IExpr t = x.accept(this);
if (t.isPresent()) {
result.set(j, t);
}
});
return result;
}
i++;
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class VisitorPlusTimesPowerReplaceAll method visitAST.
@Override
protected IExpr visitAST(IAST ast) {
if (ast.isPower()) {
IExpr base = ast.base().accept(this);
return base.isPresent() ? ast.setAtCopy(1, base) : F.NIL;
}
int i = fOffset;
int size = ast.size();
IExpr temp;
while (i < size) {
temp = ast.get(i).accept(this);
if (temp.isPresent()) {
// something was evaluated - return a new IAST:
IASTMutable result = ast.setAtCopy(i++, temp);
ast.forEach(i, size, (x, j) -> {
IExpr t = x.accept(this);
if (t.isPresent()) {
result.set(j, t);
}
});
return result;
}
i++;
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class VisitorReplaceAll method visit.
/**
* @return <code>F.NIL</code>, if no evaluation is possible
*/
@Override
public IExpr visit(IAssociation assoc) {
IExpr replacement = fFunction.apply(assoc);
if (replacement.isPresent()) {
return replacement;
}
int size = assoc.size();
for (int i = fOffset; i < size; i++) {
IExpr temp = assoc.getValue(i).accept(this);
if (temp.isPresent()) {
// something was evaluated - return a new IAST:
IAST iRuleOrNIL = assoc.getRule(i);
IASTMutable result;
if (iRuleOrNIL.isPresent()) {
result = assoc.setAtCopy(i, iRuleOrNIL.setAtCopy(2, temp));
} else {
result = assoc.copy();
}
assoc.forEach(i + 1, size, (x, j) -> {
IExpr t = x.accept(this);
if (t.isPresent()) {
result.set(j, assoc.getRule(j).setAtCopy(2, t));
}
});
return postProcessing(result);
}
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IASTMutable in project symja_android_library by axkr.
the class VisitorReplaceAllWithPatternFlags method visit.
@Override
public IExpr visit(IASTMutable ast) {
if (ast.isPatternMatchingFunction()) {
return F.NIL;
}
int i = fOffset;
int size = ast.size();
IASTMutable result = F.NIL;
while (i < size) {
IExpr temp = ast.get(i).accept(this);
if (temp.isPresent()) {
// something was evaluated - return a new IAST:
result = ast.setAtCopy(i++, temp);
while (i < size) {
temp = ast.get(i).accept(this);
if (temp.isPresent()) {
result.set(i, temp);
}
i++;
}
if (result.isAST()) {
return EvalAttributes.simpleEval(result);
// if (result.isFlatAST()) {
// IASTAppendable flattened = EvalAttributes.flattenDeep((IAST) result);
// if (flattened.isPresent()) {
// result = flattened;
// }
// }
// if (result.isOneIdentityAST1()) {
// return result.first();
// } else if (result.isOrderlessAST()) {
// EvalAttributes.sort((IASTMutable) result);
// }
// ((IAST) result).addEvalFlags(ast.getEvalFlags() & IAST.CONTAINS_PATTERN_EXPR);
}
// }
return result;
}
i++;
}
return F.NIL;
}
Aggregations