|
|
|
|
|
- Overview
- Type inference: assignment by copying
- Syntaxes
- Operating mode
- The simple types supported by the assignment by copy
- Type inference: assignment by reference
- Syntaxes
The type inference is used to simplify the declaration of variables when the variable type can be automatically deduced by the compiler. The process is very simple. The variable type is deduced according to the value that is assigned to the variable. The value can be assigned: Type inference: assignment by copying Syntaxes 1. Simple inference: soit <Variable> = <Valeur> where: - <Variable> corresponds to the name of variable to declare.
- <Value> corresponds to the value assigned to the variable to declare.
2. Multiple inference: soit (<Variable 1>, ..., <Variable N>) = (<Valeur 1>, ..., <Valeur N>) where: - ... are the names of the variables to be declared.
- ... correspond to the values assigned to each variable to be declared.
Operating mode During the assignment by copy, if the variable type can be defined during the compilation, the variable is declared according to the type of value. A copy of value is assigned to the variable. Examples: let Montant = 1500.69
let Ville = "Montpellier"
let (x, y) = (1, "A")
let (x, y) = MaProcédureARetourMultiple()
Note: The variable retains its type and does not change type during execution, even if another value of a different type is assigned to it. If the variable type cannot be defined during the compilation, the type will be defined during the execution, dynamically (like when a procedure parameter has no type). For example:
PROCEDURE MaProc(Param1)
let MaVar = Param1
The simple types supported by the assignment by copy The simple types supported by the assignment by copy are as follows: | | Type of value | Type used |
---|
boolean | boolean | 1-byte unsigned integer | int | 2-byte unsigned integer | int | 4-byte unsigned integer | 4-byte unsigned integer | 8-byte unsigned integer | 8-byte unsigned integer | 1-byte integer | int | 2-byte integer | int | int | int | 8-byte integer | 8-byte integer | currency | currency | decimal | decimal | 4-byte real | 4-byte real | real | real | character | character | string | string (Ansi or Unicode) | string of N | string (Ansi or Unicode) | ANSI string | ANSI string | Ansi string of N | ANSI string | Unicode string | Unicode string | Unicode string on N | Unicode string | ASCIIZ string of N | ANSI string | Fixed string of N | ANSI string | Pascal string of N | ANSI string | buffer | buffer | date | date | time | time | datetime | datetime | duration | duration | font | font | procedure | procedure |
Type inference: assignment by reference Syntaxes 1. Simple inference: soit <Variable> <- <Valeur> where: - <Variable> corresponds to the name of variable to declare.
- <Value> corresponds to the value assigned to the variable to declare.
2. Multiple inference: soit (<Variable 1>, ..., <Variable N>) <- (<Valeur 1>, ..., <Valeur N>) where: - ... are the names of the variables to be declared.
- ... correspond to the values assigned to each variable to be declared.
The assignment by reference is available for the complex types only: - Object type: Class, Structure, .NET Class, advanced type, ...
- Container type: Array, Associative array, Stack, Queue, List, ...
When assigning by reference, the value of the reference variable is not copied to the new variable but the new variable points to the reference variable. In this case, if the reference variable is modified, the new variable is also modified. Example: clMonClient is cClient
let clClient <- clMonClient
tabPrix is array of 5 currencies
tabPrix[1] = 500.00
tabPrix[2] = 250
let tPrix <- tabPrix
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|