Class Lambda
- All Implemented Interfaces:
Expression
A lambda expression in the RiskScape language is a self-contained expression that can be applied to a list of
arguments. A lambda expression can be in the form: ( [ARG1[, ARGn]] ) -> EXPRESSION or ARG -> EXPRESSION for a
one-arg lambda.
A classic example for the use of a lambda function is for applying a mapping operation to a list - this can be
expressed with a lambda expression like so: map([1, 2, 3, 4], element -> element * 2).
-
Constructor Summary
ConstructorsConstructorDescriptionLambda(Token left, List<Token> arguments, Expression expression) Creates a newLambdainstance. -
Method Summary
Modifier and TypeMethodDescription<T,R> R accept(ExpressionVisitor<T, R> visitor, T data) protected voidappendSource(StringBuilder appendTo) Implementers extend this to append their source to the given string builder.protected booleanbooleanNames of the arguments as given in the sourceThe expression to be evaluated, scoped to the list of argumentsgetLeft()inthashCode()final StringtoSource()final StringtoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface nz.org.riskscape.rl.ast.Expression
isA
-
Constructor Details
-
Lambda
Creates a new
Lambdainstance.- Parameters:
left-arguments- Names of the arguments as given in the sourceexpression- The expression to be evaluated, scoped to the list of arguments
-
-
Method Details
-
getBoundary
- Returns:
- a pair of tokens that represent the start and end of this expression, to be used when giving users information about where errors have occurred. If the expression has been rebuilt then the boundary may be empty or it may be from the original expression. Intended for use in problems to trace errors back to their source.
-
accept
-
appendSource
Implementers extend this to append their source to the given string builder. Done via string builder to encourage a more efficient implementation than is possible with concatenating multiple toString calls that typically contruct a string builder anyway.
-
equals
-
canEqual
-
hashCode
public int hashCode() -
getLeft
-
getArguments
Names of the arguments as given in the source
-
getExpression
The expression to be evaluated, scoped to the list of arguments
-
toString
-
toSource
- Specified by:
toSourcein interfaceExpression- Returns:
- a normalized version of the AST that can be parsed to be exactly the same AST as this
-