| Gentee Programming Language > Documentation > Syntax | Download documentation |
The collection type is used to initialize arrays and structures; furthermore, you can apply this type to pass a variable number of arguments of different types to functions. The collections are defined with the help of the percent sign and curly braces %{ ... }. Global variables can be initialized by collections which contain only constants.
global
{
arr months of str = %{"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November","December" }
}In order to initialize a structure with the help of collection, the appropriate assignment operator is required to be defined.
type test
{
uint num
str string
}
operator test =( test left, collection right )
{
if right.gettype( 0 ) != uint : return left
left.num = right.val( 0 )
if right.gettype( 1 ) != str : return left
left.string = right.val( 2 )->str
return left
}After that, a value is assigned to the fields, as follows:
test myt
myt = %{ 10, "test string" }Using the collection argument in the function, you are able to pass a variable number of arguments of different types.
func outvals( collection cl )
{
uint i
fornum i,*cl
{
print("\(i) = \(cl.val( i ))\n")
}
}The function call has the form.
outvals( %{ 10, 20, 30, 40 })The collection type is required in order to define the collection argument. To get to know more about methods and operations applied for collection, please go to the section Standard Library-Collections.
<const collection> ::= '%{' <constant> {','<constant>} '}'
<collection> ::= '%{' <expression> {','<expression>} '}'
Copyright © 2004-2006 Gentee Inc. All rights reserved. |