public final class Closure
extends java.lang.Object
(lambda (var_1 ... var_N) exp)returns a instance of the
Closure
consisting of its
arity N
, the current lexical environment, and
the body exp
.
It has convenience methods that allow a closure to be applied
to a sequence of values.
Closures are used heavily in event handling in
the g2d.glyph
package.Modifier | Constructor and Description |
---|---|
protected |
Closure(int arity,
java.lang.Object body,
Environment env,
g2d.jlambda.Continuation k,
Interpreter engine)
Constructs a Closure object.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
applyClosure()
A convenience method.
|
java.lang.Object |
applyClosure(java.lang.Object arg0)
A convenience method.
|
java.lang.Object |
applyClosure(java.lang.Object arg0,
java.lang.Object arg1)
A convenience method.
|
java.lang.Object |
applyClosure(java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2)
A convenience method.
|
java.lang.Object |
applyClosure(java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3)
A convenience method.
|
java.lang.Object |
applyClosure(java.lang.Object arg0,
java.lang.Object arg1,
java.lang.Object arg2,
java.lang.Object arg3,
java.lang.Object arg4)
A convenience method.
|
int |
getArity()
Returns the closure's arity.
|
protected java.lang.Object |
getBody()
Returns the closure's body.
|
protected Environment |
getEnv()
Returns the closure's environment.
|
java.lang.String |
toString()
A string representation of the closure.
|
protected Closure(int arity, java.lang.Object body, Environment env, g2d.jlambda.Continuation k, Interpreter engine) throws EvaluateError
arity
- an int specifying the arity of the closure. Thunks, zero arity closures,
are allowed. Negative arities are not allowed.body
- an Object representing the body of the closure.env
- an Environment object representing the environment of the closure.k
- a Continuation object, used for providing information if an exceptionengine
- the interpreter (namespace) that the cosure belongs to.
needs to be throw.EvaluateError
- in the case the the airty is negative, or the environment is null.public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.Object getBody()
protected Environment getEnv()
public int getArity()
public java.lang.Object applyClosure()
public java.lang.Object applyClosure(java.lang.Object arg0)
arg0
- the first argument to the closure.public java.lang.Object applyClosure(java.lang.Object arg0, java.lang.Object arg1)
arg0
- the first argument to the closure.arg1
- the second argument to the closure.public java.lang.Object applyClosure(java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2)
arg0
- the first argument to the closure.arg1
- the second argument to the closure.arg2
- the third argument to the closure.public java.lang.Object applyClosure(java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
arg0
- the first argument to the closure.arg1
- the second argument to the closure.arg2
- the third argument to the closure.arg3
- the fourth argument to the closure.public java.lang.Object applyClosure(java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
arg0
- the first argument to the closure.arg1
- the second argument to the closure.arg2
- the third argument to the closure.arg3
- the fourth argument to the closure.arg4
- the fifth argument to the closure.