edu.vub.at.objects
Interface Table


 Table

ATTable is the public interface to a native AmtientTalk table (an array). Extends the ATExpression interface as a Table may also be output by the parser as a literal. An important distinction between ATTables and other languages such as Java is that ATTable objects are indexed from [1..size]

Author:
tvcutsem

Method Summary
 Table +(Table other)
          Concatenation infix operator.
 Object at(Number index)
          Returns the value of the element at the index passed as argument.
 Object atPut(Number index, Object value)
          Sets the value of the element at the specified index to the new value passed as argument.
 Boolean contains(Object obj)
          Returns true if and only if there exists an element e in the table for which 'obj == e' evaluates to true.
 Nil each:(Closure code)
          Applies a closure to each element of the table.
 Table filter:(Closure code)
          Returns a new table containing only those elements of the table for which the closure evaluates to true.
 Object find:(Closure code)
          Returns the index of the first element for which the given predicate returns true.
 Text implode()
          Implodes the receiver table of characters into a text string.
 Object inject:into:(Object init, Closure code)
          Collects all elements of the table by combining them using the given closure.
 Boolean isEmpty()
          Checks if the table is empty
 Text join(Text sep)
          Joins all the text elements of the receiver table into a text string where the given text is used as a separator.
 Number length()
          Returns the length of the table
 Table map:(Closure code)
          Maps a closure over each element of the table, resulting in a new table.
 Table select(Number start, Number stop)
          Selects the subrange of the table specified by the given limits.
 
Methods inherited from interface edu.vub.at.objects.AbstractGrammar
freeVariables
 
Methods inherited from interface edu.vub.at.objects.Object
super
 

Method Detail

length

Number length()
Returns the length of the table

Returns:
the length of the table as an Number.

at

Object at(Number index)
Returns the value of the element at the index passed as argument.

Parameters:
index - a position in the table.
Returns:
ATObject representing the value of the element at the specified index.
Throws:
XTypeMismatch - if the index is not an ATNumber.
XIndexOutOfBounds - if the index is negative or if it is greater than the length of the table.

atPut

Object atPut(Number index,
             Object value)
Sets the value of the element at the specified index to the new value passed as argument.

Parameters:
index - a position in the table at which the given element is to be stored.
value - the element to be stored.
Returns:
value an Object representing the value stored in the table at the given index - i.e. the value argument.
Throws:
XTypeMismatch - if the index is not an ATNumber or if the value is not an ATObject.
XIndexOutOfBounds - if the index is negative or if it is greater than to the length of the table

isEmpty

Boolean isEmpty()
Checks if the table is empty

Returns:
true if the size of the table is zero. Otherwise, false.

each:

Nil each:(Closure code)
Applies a closure to each element of the table.

Usage example: [1,2,3].each: { |i| system.println(i) }

Parameters:
code - a closure that takes one argument and is applied to each element of the table.
Returns:
nil
Throws:
edu.vub.at.exceptions.InterpreterException - if raised inside the code closure.

map:

Table map:(Closure code)
Maps a closure over each element of the table, resulting in a new table.

Usage example: [1,2,3].map: { |i| i + 1 } returns "[2, 3, 4]"

Parameters:
code - a closure that takes one argument and is applied to each element of the table.
Returns:
nil
Throws:
edu.vub.at.exceptions.InterpreterException - if raised inside the code closure.

inject:into:

Object inject:into:(Object init,
                    Closure code)
Collects all elements of the table by combining them using the given closure. The first time closure is called, the given initializing element is passed as first argument.

Usage example: result := [1,2,3].inject: 0 into: { |total, next| total + next } where the value of result is 6.

Parameters:
init - an ATObject passed as first argument the first time the closure is called.
code - a closure that takes one argument and is applied to each element of the table.
Returns:
Object representing the value of the last applied closure.
Throws:
XIndexOutOfBounds - if the index is negative or if it is greater than the length of the table
edu.vub.at.exceptions.InterpreterException - if raised inside the code closure.

filter:

Table filter:(Closure code)
Returns a new table containing only those elements of the table for which the closure evaluates to true.

Usage example: [1,2,3].filter: {|e| e != 2 } returns [1, 3]

Parameters:
code - a closure that takes one argument and is applied to each element of the table.
Returns:
ATTable containing those elements of the table for which the closure evaluates to true.
Throws:
edu.vub.at.exceptions.InterpreterException - if raised inside the code closure.

find:

Object find:(Closure code)
Returns the index of the first element for which the given predicate returns true.

Returns nil if no element satisfying the closure can be found.

Usage example: [`a, `b, `c].find: { |e| e == `d } returns nil

Parameters:
code - a closure that takes one argument and is applied to each element of the table.
Returns:
Number representing the index of the first element for which the given closure evaluates to true. Otherwise, nil.
Throws:
edu.vub.at.exceptions.InterpreterException - if raised inside the code closure.

contains

Boolean contains(Object obj)
Returns true if and only if there exists an element e in the table for which 'obj == e' evaluates to true.

Usage example: [`a, `b, `c].contains(`d) returns false

Parameters:
obj - the element to find in the table
Returns:
true if exists an element in the table for which 'obj == e' evaluates to true. Otherwise, false.

implode

Text implode()
Implodes the receiver table of characters into a text string.

Returns:
the Text resulting of the implosion of the table.

join

Text join(Text sep)
Joins all the text elements of the receiver table into a text string where the given text is used as a separator.

Parameters:
sep - a text used as separator in the resulting text string.
Returns:
an Text resulting of the join of all the text elements of the receiver using the sep text as separator.

select

Table select(Number start,
             Number stop)
Selects the subrange of the table specified by the given limits.

Usage example: [a, b, c, d, e].select(2,4) returns [b, c]

Parameters:
start - a number representing the lower limit of the range, inclusive.
stop - a number representing the upper limit of the range, not inclusive.
Returns:
an ATTable resulting of the selection.

+

Table +(Table other)
Concatenation infix operator. Returns the concatenation of the receiver table and the given table.

Usage example: [1,2,3] + [4,5] returns [1,2,3,4,5]

Parameters:
other - a table to concatenate to the receiver table.
Returns:
an ATTable containing the elements of the receiver table and then the elements of the other table.