def a = 1 def c = {a} assert c() == 1To be able to use a Closure in this way with your own subclass, you need to provide a doCall method with any signature you want to. This ensures that {@link #getMaximumNumberOfParameters()} and {@link #getParameterTypes()} will work too without any additional code. If no doCall method is provided a closure must be used in its long form like
def a = 1 def c = {a} assert c.call() == 1@author James Strachan @author John Wilson @author Jochen Theodorou @author Graeme Rocher @author Paul King @version $Revision: 22366 $
This Closure is designed for use when the value is only read once. If the value is read more than once, a new iterator over the underlying expression is obtained each time: this may (for example in the case of a filter expression) involve significant re-calculation.
The expression may depend on local variables and on the context item; these values are held in the saved XPathContext object that is kept as part of the Closure, and they will always be read from that object. The expression may also depend on global variables; these are unchanging, so they can be read from the Bindery in the normal way. Expressions that depend on other contextual information, for example the values of position(), last(), current(), current-group(), should not be evaluated using this mechanism: they should always be evaluated eagerly. This means that the Closure does not need to keep a copy of these context variables.
Closure
represents a block of code which is executed from inside some block, function or iteration. It operates an input object. Standard implementations of common closures are provided by {@link ClosureUtils}. These include method invokation and for/while loops.
@author James Strachan
@author Nicola Ken Barozzi
@author Stephen Colebourne
@version $Revision: 1.1 $ $Date: 2005/10/11 17:05:19 $
@since Commons Collections 1.0
Each closure should have exactly one method named 'invoke' which will be invoked when the signal is triggered from gstreamer
This Closure is designed for use when the value is only read once. If the value is read more than once, a new iterator over the underlying expression is obtained each time: this may (for example in the case of a filter expression) involve significant re-calculation.
The expression may depend on local variables and on the context item; these values are held in the saved XPathContext object that is kept as part of the Closure, and they will always be read from that object. The expression may also depend on global variables; these are unchanging, so they can be read from the Bindery in the normal way. Expressions that depend on other contextual information, for example the values of position(), last(), current(), current-group(), should not be evaluated using this mechanism: they should always be evaluated eagerly. This means that the Closure does not need to keep a copy of these context variables.
In R functions are objects and can be manipulated in much the same way as any other object. Functions (or more precisely, function closures) have three basic components: a formal argument list, a body and an environment.
A closure evaluates a single argument against some expression. For example, a "StringLength" closure might accept any object and return the length of the object's string form. @author Keith Donald
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|