|
![]() |
||||||||||||||
Tuple TutorialTupleTuple is fixed size structured data type. While single tuple may consist of elements of different types, the type of each element is fixed. Tuple data type is written as Tuple[<el1-type>, <el2-type>, ..., <eln-type>]. Tuple literals begin by {# and end by #}, with elements separated by commas. Tuple may not be empty. Braces are used not only for literal tuple specification, but also as a tuple construction operator. Several tuples are presented in the following example, with their types described in comments. In many of presented examples tuples are used to define the evaluation of multiple values. Source code:// Tuple[ // Tuple[Integer], // Tuple[Integer, String], // Tuple[Integer,Tuple[String,List[Integer]]] // ] {# // Tuple[Integer] {# 1 #}, // Tuple[Integer, String] {# 1 + 2,'a'+'b' #}, // Tuple[Integer, Tuple[String, List[Integer]]] {# 1,{# 'list',[1,2,3] #}#} #} Result:{# {# 1 #}, {# 3, "ab" #}, {# 1, {# "list", [1,2,3] #} #} #}
|
|
||||||||||||||
© 2006 Saša Malkov | |||||||||||||||