Class MacroFunction

All Implemented Interfaces:
JepComponent, PostfixMathCommandI, Serializable

public class MacroFunction extends PostfixMathCommand implements JepComponent
A function specified by a string. For example
 MacroFunction fact = new MacroFunction(
            "fact",new String[]{"x"}, 
            "if(x>1,x*fact(x-1),1)");
 jep.addFunction("fact",fact);
 fact.init(jep);
 Node n = jep.parse("fact(5)");
 
Author:
R Morris.
See Also:
  • Field Details

    • nParam

      protected final int nParam
    • varNames

      protected final String[] varNames
    • expression

      protected final String expression
    • preCompiled

      protected final Node preCompiled
    • topNode

      protected transient Node topNode
    • ev

      protected transient Evaluator ev
    • vars

      protected transient Variable[] vars
  • Constructor Details

    • MacroFunction

      public MacroFunction(Jep jep, String funName, String[] parameters, String expression)
      Create a macro function with two or more arguments defined by an expression.
      Parameters:
      jep - The jep instance
      funName - name of the function
      parameters - an array of the formal parameter names used by the function
      expression -
      Since:
      3.4.0
    • MacroFunction

      public MacroFunction(Jep jep, String funName, String parameter, String expression)
      Create a macro function with a single arguments defined by an expression.
      Parameters:
      jep - The jep instance
      funName - name of the function
      parameter - the name of the formal parameter.
      expression -
      Since:
      3.4.0
    • MacroFunction

      public MacroFunction(String funName, String[] parameters, String expression)
      Create a macro function with two or more arguments defined by an expression. Use this method for recursive functions like factorial. The init(Jep) method must be called after the function is added to the function table, which will recompile the function.
      Parameters:
      funName - name of the function
      parameters - an array of the formal parameter names used by the function
      expression -
    • MacroFunction

      public MacroFunction(String funName, String[] parameters, String expression, Node root)
      Create a MacroFunction with a node tree. The ImportationVisitor is used to convert the tree into context for this object.
      Parameters:
      funName - function name
      parameters - list of parameters
      expression - string representation of equation
      root - root of expressions tree.
      Since:
      4.0
  • Method Details