edu.vub.at.objects
Interface ATClosure

All Superinterfaces:
ATConversions, ATObject
All Known Subinterfaces:
ATJavaClosure
All Known Implementing Classes:
JavaClosure, NATClosure

public interface ATClosure
extends ATObject

The public interface to a native AmbientTalk closure (a method + enclosing environment). Since ATMethods 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.

Author:
smostinc, tvcutsem

Method Summary
 ATObject base_apply(ATTable args)
          Applies the closure to the given arguments, already wrapped in a table.
 ATObject base_applyInScope(ATTable args, ATObject scope)
          Applies the closure to the given arguments, already wrapped in a table.
 ATObject base_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.
 ATContext base_getContext()
          Structural access to the scope of the closure.
 ATMethod base_getMethod()
          Structural access to the encapsulated method.
 ATObject base_whileTrue_(ATClosure 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.ATObject
base__opeql__opeql_, base_init, base_new, meta_addField, meta_addMethod, meta_assignField, meta_assignVariable, meta_clone, meta_defineField, meta_doesNotUnderstand, meta_eval, meta_extend, meta_getDynamicParent, meta_getLexicalParent, meta_getStripes, meta_grabField, meta_grabMethod, meta_invoke, meta_isCloneOf, meta_isRelatedTo, meta_isStripedWith, meta_listFields, meta_listMethods, meta_lookup, meta_newInstance, meta_pass, meta_print, meta_quote, meta_receive, meta_resolve, meta_respondsTo, meta_select, meta_send, meta_share
 
Methods inherited from interface edu.vub.at.objects.coercion.ATConversions
asAmbientTalkObject, asJavaClassUnderSymbiosis, asJavaObjectUnderSymbiosis, asNativeBoolean, asNativeException, asNativeFarReference, asNativeFraction, asNativeNumber, asNativeNumeric, asNativeTable, asNativeText, base_asActorMirror, base_asAsyncMessage, base_asBegin, base_asBoolean, base_asClosure, base_asDefinition, base_asExpression, base_asFarReference, base_asField, base_asHandler, base_asMessage, base_asMessageCreation, base_asMethod, base_asMirror, base_asNumber, base_asSplice, base_asStatement, base_asStripe, base_asSymbol, base_asTable, base_asUnquoteSplice, base_asVariableAssignment, base_isBoolean, base_isCallFrame, base_isClosure, base_isFarReference, base_isMessageCreation, base_isMethod, base_isMirror, base_isSplice, base_isStripe, base_isSymbol, base_isTable, base_isUnquoteSplice, base_isVariableAssignment, isAmbientTalkObject, isJavaObjectUnderSymbiosis, isNativeBoolean, isNativeField, isNativeText
 

Method Detail

base_getMethod

public ATMethod base_getMethod()
                        throws InterpreterException
Structural access to the encapsulated method.

Throws:
InterpreterException

base_getContext

public ATContext base_getContext()
                          throws InterpreterException
Structural access to the scope of the closure.

Throws:
InterpreterException

base_apply

public ATObject base_apply(ATTable args)
                    throws InterpreterException
Applies the closure to the given arguments, already wrapped in a table. The enclosed method is executed in the context provided by the closure.

Parameters:
args - the already evaluated arguments, wrapped in a table
Returns:
the value of evaluating the method body in the context of the closure
Throws:
InterpreterException

base_applyInScope

public ATObject base_applyInScope(ATTable args,
                                  ATObject scope)
                           throws InterpreterException
Applies the closure to the given arguments, already wrapped in a table. The enclodes method is executed in the context of the given object. The enclosed closure context is disregarded. The context provided by an object is always equal to: ctx(cur=object,self=object,super=object.dynamicParent)

Parameters:
args - the already evaluated arguments, wrapped in a table
scope - the object that will act as self and as lexically enclosing scope.
Returns:
the value of evaluating the method body in the context of the given object scope
Throws:
InterpreterException

base_whileTrue_

public ATObject base_whileTrue_(ATClosure body)
                         throws InterpreterException
Allows AmbientTalk programmers to write { booleanCondition }.whileTrue: { body } which will execute body as long as the boolean condition evaluates to true.

Throws:
InterpreterException

base_escape

public ATObject base_escape()
                     throws InterpreterException
{ |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 an XIllegalOperation exception.

Throws:
InterpreterException