|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Closure
ATClosure is the public interface to a native AmbientTalk closure (a method + enclosing environment).
Since Method
s are always wrapped either at creation time (blocks) or during
lookup (methods), ATClosures are by definition the only way methods and blocks
can be encountered at the AmbientTalk base level.
Closures should respond to the base_apply method, which should trigger the invocation of their encapsulating method in the enclosed closure context.
Closures are sometimes also 'abused' to simply represent blocks of source code whose body has to be evaluated not in the enclosed lexical context, but within the context of another object. To facilitate such use, a closure provides the method 'base_applyInScope' which will execute the enclosed method in the scope of the given object, rather than in the enclosed lexical context.
Method Summary | |
---|---|
Object |
apply(Table args)
Applies the closure to the given arguments, already wrapped in a table. |
Object |
applyInScope(Table args,
Object scope)
Applies the closure to the given arguments, already wrapped in a table. |
Context |
context()
Returns the scope of the closure. |
Object |
escape()
Escape control construct { |quit| ... quit(val) ... }.escape()
The escape control construct passes to its receiver block a function which
when invoked, immediately transfers control back to the caller of escape,
returning the value passed to quit. |
Method |
method()
Returns the encapsulated method. |
Object |
whileTrue:(Closure body)
Allows AmbientTalk programmers to write { booleanCondition }.whileTrue: { body }
which will execute body as long as the boolean condition evaluates to true. |
Methods inherited from interface edu.vub.at.objects.Object |
---|
super |
Method Detail |
---|
Method method()
Method
that returns the encapsulated method.Context context()
Method
that returns the scope of the closure.Object apply(Table args)
args
- the already evaluated arguments, wrapped in a table.
Object applyInScope(Table args, Object scope)
The context provided by an object is always equal to: ctx(cur=object,self=object,super=object.dynamicParent)
args
- the already evaluated arguments, wrapped in a table.scope
- the object that will act as self and as lexically enclosing scope.
Object whileTrue:(Closure body)
{ booleanCondition }.whileTrue: { body }
which will execute body as long as the boolean condition evaluates to true.
More specifically, what the native implementation (expressed in AmbientTalk syntax) does is:
def whileTrue: body {
self.apply().ifTrue: {
body();
self.whileTrue: body
}
}
body
- the block of code that will be executed as long as the boolean condition evaluates to true.
edu.vub.at.exceptions.InterpreterException
- if raised inside the code closure.Object escape()
{ |quit| ... quit(val) ... }.escape()
The escape control construct passes to its receiver block a function which when invoked, immediately transfers control back to the caller of escape, returning the value passed to quit.
If no value is passed to quit, nil is returned instead.
If quit is not invoked during the execution of the receiver block, the block terminates normally, with its normal return value.
If quit is invoked at the point where the call to escape has already returned,
either normally or via an exception or another escape call,
invoking quit will raise a IllegalOperation
exception.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |