Search in sources :

Example 1 with RuleCreationError

use of org.matheclipse.core.eval.exception.RuleCreationError in project symja_android_library by axkr.

the class PatternMatching method setDownRule.

public static Object[] setDownRule(IExpr leftHandSide, IExpr rightHandSide, boolean packageMode) {
    final Object[] result = new Object[] { null, rightHandSide };
    if (leftHandSide.isAST()) {
        final ISymbol lhsSymbol = ((IAST) leftHandSide).topHead();
        result[0] = lhsSymbol.putDownRule(ISymbol.RuleType.SET, false, leftHandSide, rightHandSide, packageMode);
        return result;
    }
    if (leftHandSide.isSymbol()) {
        final ISymbol lhsSymbol = (ISymbol) leftHandSide;
        if (lhsSymbol.hasLocalVariableStack()) {
            lhsSymbol.set(rightHandSide);
            return result;
        }
        result[0] = lhsSymbol.putDownRule(ISymbol.RuleType.SET, true, leftHandSide, rightHandSide, packageMode);
        return result;
    }
    throw new RuleCreationError(leftHandSide);
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IPatternObject(org.matheclipse.core.interfaces.IPatternObject) IAST(org.matheclipse.core.interfaces.IAST) RuleCreationError(org.matheclipse.core.eval.exception.RuleCreationError)

Example 2 with RuleCreationError

use of org.matheclipse.core.eval.exception.RuleCreationError in project symja_android_library by axkr.

the class PatternMatching method setDelayedDownRule.

public static Object[] setDelayedDownRule(IExpr leftHandSide, IExpr rightHandSide, boolean packageMode) {
    final Object[] result = new Object[] { null, rightHandSide };
    if (leftHandSide.isAST()) {
        final ISymbol lhsSymbol = ((IAST) leftHandSide).topHead();
        result[0] = lhsSymbol.putDownRule(ISymbol.RuleType.SET_DELAYED, false, leftHandSide, rightHandSide, packageMode);
        return result;
    }
    if (leftHandSide.isSymbol()) {
        final ISymbol lhsSymbol = (ISymbol) leftHandSide;
        if (lhsSymbol.hasLocalVariableStack()) {
            lhsSymbol.set(rightHandSide);
            return result;
        }
        result[0] = lhsSymbol.putDownRule(ISymbol.RuleType.SET_DELAYED, true, leftHandSide, rightHandSide, packageMode);
        return result;
    }
    throw new RuleCreationError(leftHandSide);
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IPatternObject(org.matheclipse.core.interfaces.IPatternObject) IAST(org.matheclipse.core.interfaces.IAST) RuleCreationError(org.matheclipse.core.eval.exception.RuleCreationError)

Example 3 with RuleCreationError

use of org.matheclipse.core.eval.exception.RuleCreationError in project symja_android_library by axkr.

the class Package method evaluate.

@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
    Validate.checkSize(ast, 4);
    if (!(ast.arg1() instanceof IStringX) || !ast.arg2().isList() || !ast.arg3().isList()) {
        throw new WrongNumberOfArguments(ast, 1, ast.size() - 1);
    }
    if (Config.SERVER_MODE) {
        throw new RuleCreationError(null);
    }
    IAST symbols = (IAST) ast.arg2();
    IAST list = (IAST) ast.arg3();
    evalPackage(symbols, list, engine);
    return F.Null;
}
Also used : IStringX(org.matheclipse.core.interfaces.IStringX) IAST(org.matheclipse.core.interfaces.IAST) WrongNumberOfArguments(org.matheclipse.core.eval.exception.WrongNumberOfArguments) RuleCreationError(org.matheclipse.core.eval.exception.RuleCreationError)

Aggregations

RuleCreationError (org.matheclipse.core.eval.exception.RuleCreationError)3 IAST (org.matheclipse.core.interfaces.IAST)3 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2 WrongNumberOfArguments (org.matheclipse.core.eval.exception.WrongNumberOfArguments)1 IStringX (org.matheclipse.core.interfaces.IStringX)1