use of org.matheclipse.core.patternmatching.PatternMatcherEquals in project symja_android_library by axkr.
the class Symbol method reassignSymbolValue.
/**
* {@inheritDoc}
*/
@Override
public IExpr[] reassignSymbolValue(Function<IExpr, IExpr> function, ISymbol functionSymbol, EvalEngine engine) {
IExpr[] result = new IExpr[2];
IExpr symbolValue;
if (hasLocalVariableStack()) {
symbolValue = get();
result[0] = symbolValue;
IExpr calculatedResult = function.apply(symbolValue);
if (calculatedResult.isPresent()) {
set(calculatedResult);
result[1] = calculatedResult;
return result;
}
} else {
if (fRulesData != null) {
PatternMatcherEquals pme = fRulesData.getEqualDownRules().get(this);
if (pme != null) {
symbolValue = pme.getRHS();
if (symbolValue != null) {
result[0] = symbolValue;
IExpr calculatedResult = function.apply(symbolValue);
if (calculatedResult.isPresent()) {
pme.setRHS(calculatedResult);
result[1] = calculatedResult;
return result;
}
}
}
}
}
engine.printMessage(toString() + " is not a variable with a value, so its value cannot be changed.");
return null;
}
use of org.matheclipse.core.patternmatching.PatternMatcherEquals in project symja_android_library by axkr.
the class Symbol method reassignSymbolValue.
/**
* {@inheritDoc}
*/
@Override
public IExpr[] reassignSymbolValue(IAST ast, ISymbol functionSymbol, EvalEngine engine) {
IExpr[] result = new IExpr[2];
IExpr symbolValue;
if (hasLocalVariableStack()) {
symbolValue = get();
result[0] = symbolValue;
// IExpr calculatedResult = function.apply(symbolValue);
ast.set(1, symbolValue);
// F.binaryAST2(this, symbolValue, value));
IExpr calculatedResult = engine.evaluate(ast);
if (calculatedResult != null) {
set(calculatedResult);
result[1] = calculatedResult;
return result;
}
} else {
if (fRulesData != null) {
PatternMatcherEquals pme = fRulesData.getEqualDownRules().get(this);
if (pme != null) {
symbolValue = pme.getRHS();
if (symbolValue != null) {
result[0] = symbolValue;
// IExpr calculatedResult = function.apply(symbolValue);
ast.set(1, symbolValue);
IExpr calculatedResult = engine.evaluate(ast);
if (calculatedResult != null) {
pme.setRHS(calculatedResult);
result[1] = calculatedResult;
return result;
}
}
}
}
}
throw new WrongArgumentType(this, functionSymbol.toString() + " - Symbol: " + toString() + " has no value! Reassignment with a new value is not possible");
}
Aggregations