|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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]
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 |
---|
Number length()
Number
.Object at(Number index)
index
- a position in the table.
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.Object atPut(Number index, Object value)
index
- a position in the table at which the given element is to be stored.value
- the element to be stored.
Object
representing the value stored in the table at the given index - i.e. the value argument.
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 tableBoolean isEmpty()
Nil each:(Closure code)
Usage example:
[1,2,3].each: { |i| system.println(i) }
code
- a closure that takes one argument and is applied to each element of the table.
edu.vub.at.exceptions.InterpreterException
- if raised inside the code closure.Table map:(Closure code)
Usage example:
[1,2,3].map: { |i| i + 1 }
returns "[2, 3, 4]"
code
- a closure that takes one argument and is applied to each element of the table.
edu.vub.at.exceptions.InterpreterException
- if raised inside the code closure.Object inject:into:(Object init, Closure code)
Usage example:
result := [1,2,3].inject: 0 into: { |total, next| total + next }
where the value of result
is 6.
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.
Object
representing the value of the last applied closure.
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.Table filter:(Closure code)
Usage example:
[1,2,3].filter: {|e| e != 2 }
returns [1, 3]
code
- a closure that takes one argument and is applied to each element of the table.
edu.vub.at.exceptions.InterpreterException
- if raised inside the code closure.Object find:(Closure code)
Returns nil if no element satisfying the closure can be found.
Usage example:
[`a, `b, `c].find: { |e| e == `d }
returns nil
code
- a closure that takes one argument and is applied to each element of the table.
Number
representing the index of the first element for which the given closure evaluates to true. Otherwise, nil.
edu.vub.at.exceptions.InterpreterException
- if raised inside the code closure.Boolean contains(Object obj)
Usage example:
[`a, `b, `c].contains(`d)
returns false
obj
- the element to find in the table
Text implode()
Text
resulting of the implosion of the table.Text join(Text sep)
sep
- a text used as separator in the resulting text string.
Text
resulting of the join of all the text elements of the receiver using the sep text as separator.Table select(Number start, Number stop)
Usage example:
[a, b, c, d, e].select(2,4)
returns [b, c]
start
- a number representing the lower limit of the range, inclusive.stop
- a number representing the upper limit of the range, not inclusive.
Table +(Table other)
Usage example:
[1,2,3] + [4,5]
returns [1,2,3,4,5]
other
- a table to concatenate to the receiver table.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |