public class AstFunction extends AstPrimitive
| Constructor and Description |
|---|
AstFunction() |
AstFunction(java.util.ArrayList<java.lang.String> ids,
AstRoot body) |
AstFunction(AstFunction fun,
Val[] args,
AstFunction parent) |
| Modifier and Type | Method and Description |
|---|---|
Val |
apply(Env env,
Env.StackHelp stk,
AstRoot[] asts)
Primary method to invoke this function, passing all the parameters
as the `asts` list.
|
java.lang.String[] |
args()
List of argument names.
|
java.lang.String |
description()
Return the detailed description (help) for what this language construct
does or how it is supposed to be used.
|
java.lang.String |
example()
Return an example of how this Ast construct ought to be used.
|
ValFun |
exec(Env env)
"Execute" this AST expression, and return the result.
|
Val |
lookup(java.lang.String id) |
int |
nargs()
Number of function's arguments + 1.
|
java.lang.String |
str()
String representation of this Ast object in the Rapids language.
|
asBytes, clone, copyOver, frozenType, read, readExternal, readJSON, reloadFromBytes, toJsonString, write, writeExternal, writeJSONpublic AstFunction()
public AstFunction(java.util.ArrayList<java.lang.String> ids,
AstRoot body)
public AstFunction(AstFunction fun, Val[] args, AstFunction parent)
public java.lang.String str()
AstRootAstPrimitives this is the name of the function; for
AstParameters this is either the name of the variable, or the
value of the numeric constant that the parameter represents. For more
complicated constructs such as AstExec or AstFunction
this method should return those objects as a Rapids string.public java.lang.String example()
AstRootReturn an example of how this Ast construct ought to be used. This
method is used to build documentation for the Rapids language. It is
different from AstRoot.str(), in particular it must provide a valid
example even in a static context. For example, an AstStr may
return "Hello, world!" as an example. At the same time,
for different AstPrimitives this method should generally provide
a typical example of how that function is to be used.
Return null to indicate that the object should not be
included in the documentation.
example in class AstPrimitivepublic java.lang.String description()
AstRootReturn the detailed description (help) for what this language construct
does or how it is supposed to be used. This method is used in conjunction
with AstRoot.example() to build the documentation of the Rapids
language.
If you need to include any formatting, then please use Markup language. Although it is up to the client to support it, Markup is one of the simplest and easiest alternatives.
Return null to indicate that the object should not be
included in the documentation.
description in class AstPrimitivepublic ValFun exec(Env env)
AstRoot"Execute" this AST expression, and return the result. For different ASTs this may have different interpretation. For example, consider this Rapids expression:
(mean frame True False)
It will be parsed into the following structure:
AstExec() instance with
_asts = [AstMean() singleton instance,
new AstId(frame),
AstConst.TRUE,
AstConst.FALSE]
Execution of AstExec will execute its first argument, _asts[0],
verify that it produces a function (ValFun), then call
AstPrimitive.apply(Env, Env.StackHelp, AstRoot[]) on that function
passing down the list of _asts arguments.
The AstMean class will in turn execute all its arguments,
where execution of AstId fetches the referred symbol from the
environment, and execution of AstConst returns the value of that
constant.
Certain other functions may choose not to evaluate all their arguments (for example boolean expressions providing short-circuit evaluation).
exec in class AstPrimitivepublic int nargs()
AstPrimitivenargs in class AstPrimitivepublic java.lang.String[] args()
AstPrimitiveargs in class AstPrimitivepublic Val lookup(java.lang.String id)
public Val apply(Env env, Env.StackHelp stk, AstRoot[] asts)
AstPrimitivePrimary method to invoke this function, passing all the parameters as the `asts` list.
apply in class AstPrimitiveenv - Current execution environment. Variables are looked up here.stk - TODO need clarificationasts - List of AstRoot expressions that are arguments to the
function. First element in this list is the function itself.