1.35Class Table

Home of tabular programming.

Class Table( [heading] )
heading The heading of the table (array)
Methods
appendAdds a row at the end of the current page in the table.
backReturns the last item in the table.
biddingPerforms a bidding between rows.
choicePerforms a choice between rows.
columnDataReturns the column data bound with a certain column
columnPosReturns the number of a given column name.
curPageGets the current table page.
findFinds an element in a table.
firstReturns an iterator to the first element of the table.
frontReturns the first item in the table.
getGets a row in a table.
getColDataGets the clumn wide data associated with this table.
getHeaderGets the name of one header, or the list of header names.
getPageReturns a copy of a given page in the table.
insertInsert a row in the table.
insertColumnInserts a column in a table.
insertPageInserts a new table page.
lastReturns an iterator to the last element of the table.
lenReturns the length of the table (the number of rows).
orderReturns the order of the table (column count).
pageCountGets the number of pages in this table.
removeRemove a row from the table.
removeColumnRemoves a column from a table.
removePageRemoves a page.
resetColumnApplies a value on a column, eventually setting one or more rows to a different value.
setChanges the value of a whole row.
setColumnChange the title or column data of a column.
setHeaderSets the header of an empty table.
setPageSets current active page.

Methods

append

Adds a row at the end of the current page in the table.

Table.append( element )
element The row to be inserted.
Raise
ParamError if element is not an array with the same length of the table order.

This method adds the element at the end of the page currently selected in this table.

Note: This method is equivalent to Table.insert with row set as nil.

back

Returns the last item in the table.

Table.back()
ReturnThe last item in the table.
Raise
AccessError if the table is empty.

If the table is not empty, it returns the last element (row) in the table.

bidding

Performs a bidding between rows.

Table.bidding( column, [offer],[rows] )
column Betting column (number or name).
offer Offer column (number or name).
rows Range of rows in which to perform the bidding.
ReturnThe winning row, or the corresponding value in the offer column.
Raise
AccessError if the table or ranges are empty.

This method calls iteratively all the items in a determined column of the table, recording their return value, which must be numeric. It is allowed also to have numeric and nil values in the cells in the betting column. Numeric values will be considered as final values and will participate in the final auction, while row having nil values will be excluded.

After the bidding is complete, the row offering the highest value is selected and returned, or if the offer parameter is specified, the corresponding value in the given column will be returned.

Note: If the bidding element is a plain function, it will be called as a method of the array, so "self" will be available. In all the other cases, the array will be passed as the last parameter.

A rows range can be specified to limit the bidding to a part smaller part of the table.

choice

Performs a choice between rows.

Table.choice( func, [offer],[rows] )
func Choice function or callable.
offer Offer column (number or name).
rows Range of rows in which to perform the bidding.
ReturnThe winning row, or the corresponding value in the offer column.

This method sends all the rows in the table as the sole parameter of a function which has to return a numeric value for each row.

After all the rows have been processed, the row for which the called function had the highest value is returned. If the optional parameter offer is specified, then the item specified by that column number or name is returned instead.

If two or more rows are equally evaluated by the choice function, only the first one is returned.

The evaluation function may return a number lower than 0 to have the row effectively excluded from the evaluation. If all the rows are evaluated to have a value lower than zero, the function returns nil (as if the table was empty).

The function may force an immediate selection by returning an out of band item. An out of band nil will force this method to return nil, and an out of band number will force the selection of the current row.

If an offer parameter is specified, then the item in the corresponding column (indicated by a numeric index or by column name) is returned.

A row range can be used to iterate selectively on one part of the table.

If the table is empty, or if the given row range is empty, the function returns nil.

Note: Except for OOB nil, every return value coming from the choice function will be turned into a floating point numeric value. Non-numeric returns will be evaluated as 0.0.

columnData

Returns the column data bound with a certain column

Table.columnData( column, [data] )
column The column header name or numeric position.
data New data to be stored as column data.
ReturnThe column data for the given column, or nil is not found.

If the data parameter is specified, then the value of the given column data is changed. Anyhow, the previous value is returned.

Notice that the column data of an existing column may be nil; to know if a column with a given name exists, use the Table.columnPos method.

columnPos

Returns the number of a given column name.

Table.columnPos( column )
column The column header name.
ReturnThe numeric position of the column or -1 if not found.

curPage

Gets the current table page.

Table.curPage()
ReturnThe currently active table page.

All the tables are created with at least one page having ID = 0.

find

Finds an element in a table.

Table.find( column, value, [tcol],[dflt] )
column The column where to perform the search (either name or 0 based number).
value The value to be found.
tcol The name of the column to be extracted (target column; either name or 0 based number).
dflt A default value to be returned if the row is not found.
ReturnAn array (if the column is not specified) or an item.
Raise
TableError if the item is not found.

The returned array is a "table component", and as such, its size cannot be changed; also, it inherits all the table columns, that can be accessed as bindings with the dot accessor and will resolve in one of the element in the array.

In case of success, through the BOM method Array.tabRow it is possible to retrieve the table row position of the returned array.

In case of failure, a TableError is raised, unless a dflt parameter is specified.

first

Returns an iterator to the first element of the table.

Table.first()
ReturnAn iterator.

Returns an iterator to the first element of the table. If the table is empty, an invalid iterator will be returned, but an insertion on that iterator will succeed and append an item to the table.

front

Returns the first item in the table.

Table.front()
ReturnThe first item in the table.
Raise
AccessError if the table is empty.

If the table is not empty, it returns the first element (row) in the table.

get

Gets a row in a table.

Table.get( row, [tcol] )
row a Row number.
tcol The name of the column to be extracted (target column; either name or 0 based number).
ReturnAn array (if the column is not specified) or an item.

The returned array is a "table component", and as such, its size cannot be changed; also, it inherits all the table clumns, that can be accessed as bindings with the dot accessor and will resolve in one of the element in the array.

getColData

Gets the clumn wide data associated with this table.

Table.getColData( [id] )
id If given, a number indicating the column of which to get the data.
ReturnAn item (if id is given) or the vector of ordered column names.

getHeader

Gets the name of one header, or the list of header names.

Table.getHeader( [id] )
id If given, a number indicating the column of which to get the name.
ReturnA string (if id is given) or the vector of ordered column names.

getPage

Returns a copy of a given page in the table.

Table.getPage( [pageId] )
pageId The page to be copied (defaults to the current page).
ReturnAn array containing all the rows in the page.

While the returned item is a copy, and modifying it doesn't cause the change the be reflected on the table, each row returned with it is the actual item stored in the table. So, modifying the Nth element of one of the arrays in the returned one will affect the page.

insert

Insert a row in the table.

Table.insert( row, element )
row The position where to insert the row.
element The row to be inserted.
Raise
AccessError if the position is out of range.
ParamError if the row is not an array with the same length of the table order.

The element is inserted before the given position.

If pos is greater or equal to the length of the table, the row will be inserted at end (added). If pos is negative, the row will be accessed backward, -1 being the last element (the row will be inserted before the last one).

insertColumn

Inserts a column in a table.

Table.insertColumn( column, name, [coldata],[dflt] )
column The column name or position where to insert the column.
name The name of the new column.
coldata The column data for the new column.
dflt Default value for the newly inserted columns.

This method creates a new column in the table, inserting or adding a new heading, a new column data and an item in the corresponding column position of each array in the table.

If dflt parameter is specified, that value is used to fill the newly created columns in the table rows, otherwise the new items will be nil.

insertPage

Inserts a new table page.

Table.insertPage( [pageId],[data] )
pageId The position at which to insert the page.
data an array of rows (arrays), each of which having length equal to table order.

If pos is greater than the number of pages in the table, or not given, the page will be appended at the end.

last

Returns an iterator to the last element of the table.

Table.last()
ReturnAn iterator.

Returns an iterator to the last element of the table. If the table is empty, an invalid iterator will be returned, but an insertion on that iterator will succeed and append an item to the table.

len

Returns the length of the table (the number of rows).

Table.len()
ReturnThe rows in the current page of the table.

Tables may have multiple pages, each of which having the same order (column count), but different length (rows).

This method returns the length of the currently active page.

order

Returns the order of the table (column count).

Table.order()
ReturnThe number of the columns, and of the length of every array in the table.

pageCount

Gets the number of pages in this table.

Table.pageCount()
ReturnNumber of pages stored in this table.

remove

Remove a row from the table.

Table.remove( row )
row The number of the row to be removed.
ReturnThe removed array.
Raise
AccessError if the position is out of range.

This method removes one of the rows from the table.

However, the array still remember the table from which it came from, as the table may have multiple reference to the array. So, the array stays bound with the table, and cannot be modified.

removeColumn

Removes a column from a table.

Table.removeColumn( column )
column The column name or position to be removed.
Raise
AccessError if the column is not found.

This method removes column in the table, removing also the item at corresponding position in all the rows of all the pages in this table.

removePage

Removes a page.

Table.removePage( pageId )
pageId The page to be removed.

The table cannot exist without at least one page, and if the deleted page is the current one, the page 0 is selected.

resetColumn

Applies a value on a column, eventually setting one or more rows to a different value.

Table.resetColumn( column, [resetVal],[row],[value] )
column Column name or number where the value must be applied.
resetVal The value that must be set to clear the rows (defaults to nil).
row The row (or rows, if a range is given) to be set to value.
value The value that must be set in the given row(s) (defaults to true).

This method takes a column in the current page and sets all the values in all the rows to resetVal (or nil if not given).

Optionally, a single row or a range of rows where to apply a different value can be given.

In example, this allows to create a diagonal matrix like the following:


     x = Table( ["a","b","c"] )
     x.insert( 0, arrayBuffer( 3 ) )
     x.insert( 0, arrayBuffer( 3 ) )
     x.insert( 0, arrayBuffer( 3 ) )

     for i in [0:3]
        x.resetColumn( i, 0, i, 1 )
     end

Tables are not meant for linear algebra calculus, but it is often useful to clear a whole column, and it can come useful to set just one row in a table to stand out, especially in decision support systems and program logic control, which is what Falcon tables are specifically designed.

set

Changes the value of a whole row.

Table.set( row, element )
row a Row number.
element The new data to be placed at the given row.

This method changes an existing row placing a completely new value over it.

setColumn

Change the title or column data of a column.

Table.setColumn( column, name, [coldata] )
column The number of name of the column to be renamed.
name The new name of the column, or nil to let it unchanged.
coldata The new column data.

This method changes the column heading in a table. It may be also used to change the column-wide data.

setHeader

Sets the header of an empty table.

Table.setHeader( header )
header An array of strings or future bindings that will be used as table header
Raise
CodeError if the table has already a valid header.

This method allows to set the header of an uninitialized table after its creation.

setPage

Sets current active page.

Table.setPage( pageId )
pageId The number of the selected page.

All the tables are created with at least one page having ID = 0.

Made with http://www.falconpl.org