Difference between revisions of "Record"
(Created page with '== Syntax == record[name<sub>1</sub>,type<sub>1</sub>,name<sub>2</sub>,type<sub>2</sub>,.....,name<sub>d</sub>,type<sub>d</sub>] == Semantics == The ''record'' type allows the…') |
m (7 revisions imported) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
The ''record'' type allows the programmer to combine ''d'' attributes into one, new type. There can be any number of names and types inside the record type. A record type is very similar to a typedef structure in C. To access the member of a record use the dot, ''.'' | The ''record'' type allows the programmer to combine ''d'' attributes into one, new type. There can be any number of names and types inside the record type. A record type is very similar to a typedef structure in C. To access the member of a record use the dot, ''.'' | ||
+ | |||
+ | === Default typing === | ||
+ | |||
+ | * [[allocated]] | ||
+ | * [[multiple]] | ||
+ | * [[stack]] | ||
+ | * [[onesided]] | ||
== Example == | == Example == | ||
− | + | function void main() { | |
− | + | typevar complex ::= record["r",Float,"i",Float]; | |
− | + | var a:array[complex, 10]; | |
− | + | var number:complex; | |
− | + | var pixel : record["r",Int,"g",Int,"b",Int]; | |
− | + | ||
− | + | a[1].r:=8.6; | |
+ | number.i:=3.22; | ||
+ | pixel.b:=128; | ||
+ | }; | ||
+ | |||
+ | In the above example, ''complex'' is declared as a [[Type_Variables|type variable]] to be a complex number. This is then used as the type chain for ''a'' which is an [[array]] and ''number''. Using records in this manner can be useful, although the other way is just to include directly in the type chain for a variable such as declaring the ''pixel'' variable. Do not get confused between the difference between ''complex'' (a type variable existing during compilation only) and ''pixel'' (a normal data variable which exists at runtime.) In the last two lines assignment occurs to the declared variables. | ||
− | + | ''Since: Version 0.41b'' | |
[[Category:Type Library]] | [[Category:Type Library]] | ||
− | [[Category: | + | [[Category:Compound Types]] |
[[Category:Composition Types]] | [[Category:Composition Types]] |
Latest revision as of 15:44, 15 April 2019
Contents
Syntax
record[name1,type1,name2,type2,.....,named,typed]
Semantics
The record type allows the programmer to combine d attributes into one, new type. There can be any number of names and types inside the record type. A record type is very similar to a typedef structure in C. To access the member of a record use the dot, .
Default typing
Example
function void main() { typevar complex ::= record["r",Float,"i",Float]; var a:array[complex, 10]; var number:complex; var pixel : record["r",Int,"g",Int,"b",Int]; a[1].r:=8.6; number.i:=3.22; pixel.b:=128; };
In the above example, complex is declared as a type variable to be a complex number. This is then used as the type chain for a which is an array and number. Using records in this manner can be useful, although the other way is just to include directly in the type chain for a variable such as declaring the pixel variable. Do not get confused between the difference between complex (a type variable existing during compilation only) and pixel (a normal data variable which exists at runtime.) In the last two lines assignment occurs to the declared variables.
Since: Version 0.41b