edu.vub.at.objects.natives
Class NATTable

java.lang.Object
  extended byedu.vub.at.objects.natives.NATNil
      extended byedu.vub.at.objects.natives.NATByCopy
          extended byedu.vub.at.objects.natives.grammar.NATAbstractGrammar
              extended byedu.vub.at.objects.natives.grammar.AGExpression
                  extended byedu.vub.at.objects.natives.NATTable
All Implemented Interfaces:
ATAbstractGrammar, ATConversions, ATExpression, ATNil, ATObject, ATStatement, ATTable, java.io.Serializable

public final class NATTable
extends AGExpression
implements ATTable

The native implementation of an AmbientTalk table. A table is implemented by a java array. An important distinction between AT tables and Java arrays is that ATTable objects are indexed from [1..size] rather than [0..size[

Author:
tvc
See Also:
Serialized Form

Field Summary
 ATObject[] elements_
           
static NATTable EMPTY
           
 
Fields inherited from class edu.vub.at.objects.natives.NATNil
_INSTANCE_
 
Constructor Summary
private NATTable(ATObject[] elements)
           
 
Method Summary
 NATTable asNativeTable()
           
static NATTable atValue(ATObject[] array)
          Table factory method.
 ATTable base__oppls_(ATTable other)
          [1,2,3] + [4,5] => [1,2,3,4,5]
 ATTable base_asTable()
           
 ATObject base_at(ATNumber index)
           
 ATObject base_atPut(ATNumber index, ATObject value)
           
 ATNil base_each_(ATClosure clo)
          Apply a closure to each element of the table
 ATTable base_filter_(ATClosure clo)
          Keep only those elements of the table for which the closure evaluates to true.
 ATObject base_find_(ATClosure clo)
          Return the index of the first element for which the given predicate returns true.
 ATNumber base_getLength()
           
 ATText base_implode()
          Implode the receiver table of characters into a text string
 ATBoolean base_isEmpty()
           
 ATText base_join(ATText sep)
          Join all the text elements of the receiver table into a text string where the argument is used as a separator
 ATTable base_map_(ATClosure clo)
          Map a closure over each element of the table, resulting in a new table.
 ATTable base_select(ATNumber first, ATNumber last)
          tab.select(start, stop) == els = [ ] ; start.to: stop do: { |i| els << tab[i] } ; els
 ATObject base_with_collect_(ATObject init, ATClosure clo)
          Collect all elements of the table by combining them using the given closure.
static ATObject[] collate(ATObject[] ary1, ATObject[] ary2)
          Auxiliary method to collate two Java arrays
protected  int extractIndex(ATNumber atIndex)
           
 ATObject meta_eval(ATContext ctx)
          To evaluate a table, evaluate all of its constituent expressions, taking special care to take into account spliced expressions.
 ATTable meta_getStripes()
          Returns the stripes of this object.
 NATText meta_print()
          Prints out the object in a human-readable way.
 ATObject meta_quote(ATContext ctx)
          To quote a table, quote all elements of the table.
 ATObject meta_resolve()
          When an object is deserialized after it has been passed to another actor, it is given a chance to tell the interpreter which object it represents.
static NATTable of(ATObject one)
           
static NATTable of(ATObject one, ATObject two)
           
static NATTable of(ATObject one, ATObject two, ATObject three)
           
 
Methods inherited from class edu.vub.at.objects.natives.grammar.AGExpression
base_asExpression
 
Methods inherited from class edu.vub.at.objects.natives.NATByCopy
meta_pass
 
Methods inherited from class edu.vub.at.objects.natives.NATNil
asAmbientTalkObject, asJavaClassUnderSymbiosis, asJavaObjectUnderSymbiosis, asNativeBoolean, asNativeException, asNativeFarReference, asNativeFraction, asNativeNumber, asNativeNumeric, asNativeText, base__opeql__opeql_, base_asActorMirror, base_asAsyncMessage, base_asBegin, base_asBoolean, base_asClosure, base_asDefinition, 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_asUnquoteSplice, base_asVariableAssignment, base_init, 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, base_new, createChild, equals, isAmbientTalkObject, isJavaObjectUnderSymbiosis, isNativeBoolean, isNativeField, isNativeText, meta_addField, meta_addMethod, meta_assignField, meta_assignVariable, meta_clone, meta_defineField, meta_doesNotUnderstand, meta_extend, meta_getDynamicParent, meta_getLexicalParent, meta_grabField, meta_grabMethod, meta_invoke, meta_isCloneOf, meta_isRelatedTo, meta_isStripedWith, meta_listFields, meta_listMethods, meta_lookup, meta_newInstance, meta_receive, meta_respondsTo, meta_select, meta_send, meta_share, readResolve, toString, writeReplace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
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_extend, meta_getDynamicParent, meta_getLexicalParent, meta_grabField, meta_grabMethod, meta_invoke, meta_isCloneOf, meta_isRelatedTo, meta_isStripedWith, meta_listFields, meta_listMethods, meta_lookup, meta_newInstance, meta_pass, meta_receive, 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, 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_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
 

Field Detail

EMPTY

public static final NATTable EMPTY

elements_

public final ATObject[] elements_
Constructor Detail

NATTable

private NATTable(ATObject[] elements)
Method Detail

atValue

public static final NATTable atValue(ATObject[] array)
Table factory method. Used to enforce that only one empty table in the system exists.


of

public static final NATTable of(ATObject one)

of

public static final NATTable of(ATObject one,
                                ATObject two)

of

public static final NATTable of(ATObject one,
                                ATObject two,
                                ATObject three)

base_asTable

public ATTable base_asTable()
Specified by:
base_asTable in interface ATConversions
Overrides:
base_asTable in class NATNil

asNativeTable

public NATTable asNativeTable()
Specified by:
asNativeTable in interface ATConversions
Overrides:
asNativeTable in class NATNil

meta_eval

public ATObject meta_eval(ATContext ctx)
                   throws InterpreterException
To evaluate a table, evaluate all of its constituent expressions, taking special care to take into account spliced expressions. NATTAB(exps).eval(ctx) = NATTAB(map eval(ctx) over exps)

Specified by:
meta_eval in interface ATObject
Overrides:
meta_eval in class NATNil
Returns:
a table of evaluated arguments
Throws:
InterpreterException

meta_quote

public ATObject meta_quote(ATContext ctx)
                    throws InterpreterException
To quote a table, quote all elements of the table. Special care needs to be taken in order to properly deal with unquote-spliced elements. When one of the direct elements of the table is an unquote-splice element, the resulting unquotation must result in a table whose elements are directly added to this table's elements.

Specified by:
meta_quote in interface ATObject
Overrides:
meta_quote in class NATNil
Throws:
InterpreterException

meta_print

public NATText meta_print()
                   throws InterpreterException
Description copied from interface: ATObject
Prints out the object in a human-readable way.

Specified by:
meta_print in interface ATObject
Overrides:
meta_print in class NATNil
Throws:
InterpreterException

meta_getStripes

public ATTable meta_getStripes()
                        throws InterpreterException
Description copied from interface: ATObject
Returns the stripes of this object. Note that only the stripes that were attached directly to this object are returned, not all of the parent's stripes as well.

Specified by:
meta_getStripes in interface ATObject
Overrides:
meta_getStripes in class AGExpression
Throws:
InterpreterException

base_getLength

public ATNumber base_getLength()
Specified by:
base_getLength in interface ATTable

base_at

public ATObject base_at(ATNumber index)
                 throws InterpreterException
Specified by:
base_at in interface ATTable
Throws:
InterpreterException

base_atPut

public ATObject base_atPut(ATNumber index,
                           ATObject value)
                    throws InterpreterException
Specified by:
base_atPut in interface ATTable
Throws:
InterpreterException

base_isEmpty

public ATBoolean base_isEmpty()
Specified by:
base_isEmpty in interface ATTable

base_each_

public ATNil base_each_(ATClosure clo)
                 throws InterpreterException
Description copied from interface: ATTable
Apply a closure to each element of the table. [ tab ].each: { |v| ... }

Specified by:
base_each_ in interface ATTable
Returns:
nil, always
Throws:
InterpreterException

base_map_

public ATTable base_map_(ATClosure clo)
                  throws InterpreterException
Description copied from interface: ATTable
Map a closure over each element of the table, resulting in a new table. result := [ tab ].map: { |v| ... }

Specified by:
base_map_ in interface ATTable
Throws:
InterpreterException

base_with_collect_

public ATObject base_with_collect_(ATObject init,
                                   ATClosure clo)
                            throws InterpreterException
Description copied from interface: ATTable
Collect all elements of the table by combining them using the given closure. The first time closure is called, the initialization element is passed as first argument. result := [ tab ].with: 0 collect: { |total, next| total + next }

Specified by:
base_with_collect_ in interface ATTable
Throws:
InterpreterException

base_filter_

public ATTable base_filter_(ATClosure clo)
                     throws InterpreterException
Description copied from interface: ATTable
Keep only those elements of the table for which the closure evaluates to true. result := [ tabl ].filter: { |elt| booleanCondition(elt) }

Specified by:
base_filter_ in interface ATTable
Throws:
InterpreterException

base_find_

public ATObject base_find_(ATClosure clo)
                    throws InterpreterException
Description copied from interface: ATTable
Return the index of the first element for which the given predicate returns true. Returns nil if no element satisfying the closure can be found. result := [ tabl ].find: { |elt| booleanCondition(elt) }

Specified by:
base_find_ in interface ATTable
Throws:
InterpreterException

base_implode

public ATText base_implode()
                    throws InterpreterException
Description copied from interface: ATTable
Implode the receiver table of characters into a text string

Specified by:
base_implode in interface ATTable
Throws:
InterpreterException

base_join

public ATText base_join(ATText sep)
                 throws InterpreterException
Description copied from interface: ATTable
Join all the text elements of the receiver table into a text string where the argument is used as a separator

Specified by:
base_join in interface ATTable
Throws:
InterpreterException

base_select

public ATTable base_select(ATNumber first,
                           ATNumber last)
                    throws InterpreterException
tab.select(start, stop) == els = [ ] ; start.to: stop do: { |i| els << tab[i] } ; els

Specified by:
base_select in interface ATTable
Throws:
InterpreterException

base__oppls_

public ATTable base__oppls_(ATTable other)
                     throws InterpreterException
Description copied from interface: ATTable
[1,2,3] + [4,5] => [1,2,3,4,5]

Specified by:
base__oppls_ in interface ATTable
Throws:
InterpreterException

extractIndex

protected int extractIndex(ATNumber atIndex)
                    throws InterpreterException
Throws:
InterpreterException

collate

public static final ATObject[] collate(ATObject[] ary1,
                                       ATObject[] ary2)
Auxiliary method to collate two Java arrays

Returns:
an array containing first the elements of ary1, then the elements of ary2

meta_resolve

public ATObject meta_resolve()
                      throws InterpreterException
Description copied from interface: ATObject
When an object is deserialized after it has been passed to another actor, it is given a chance to tell the interpreter which object it represents. Normally, by copy objects just return 'this' because they represent themselves. Far references, however, will try to 'resolve' themselves into a near reference when possible.

Specified by:
meta_resolve in interface ATObject
Overrides:
meta_resolve in class NATByCopy
Throws:
InterpreterException