|
- Overview
- Type inference: assignment by copy
- 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 principle is straightforward. The variable type is deduced according to the value that is assigned to the variable. The value can be assigned: Versions 26 and later New in version 26 Type inference: assignment by copy Syntaxes 1. Simple inference: where: - <Variable> corresponds to the name of variable to declare.
- <Value> corresponds to the value assigned to the variable to declare.
Versions 19 and later2. Multiple inference:
let (<Variable 1>, ..., <Variable N>) = (<Value 1>, ..., <Value N>)
where: - <Variable 1> ... <Variable N> correspond to the names of variables to declare.
- <Value 1> ... <Value N> correspond to the values assigned to each variable to declare.
New in version 192. Multiple inference:
let (<Variable 1>, ..., <Variable N>) = (<Value 1>, ..., <Value N>)
where: - <Variable 1> ... <Variable N> correspond to the names of variables to declare.
- <Value 1> ... <Value N> correspond to the values assigned to each variable to declare.
2. Multiple inference:
let (<Variable 1>, ..., <Variable N>) = (<Value 1>, ..., <Value N>)
where: - <Variable 1> ... <Variable N> correspond to the names of variables to declare.
- <Value 1> ... <Value N> correspond to the values assigned to each variable to declare.
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 Amount = 1500.69 // real type
let City = "Montpellier" // string type
Versions 19 and later
// Multiple inference let (x, y) = (1, "A")
// Multiple inference via a procedure returning multiple values let (x, y) = MyProcedureWithMultipleReturns()
New in version 19
// Multiple inference let (x, y) = (1, "A")
// Multiple inference via a procedure returning multiple values let (x, y) = MyProcedureWithMultipleReturns()
// Multiple inference let (x, y) = (1, "A")
// Multiple inference via a procedure returning multiple values let (x, y) = MyProcedureWithMultipleReturns()
Remark: The variable keeps its type ; its type does not change during the 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:
// Case of unknown type during the compilation PROCEDURE MyProc(Param1) let MyVar = Param1 // As the Param1 parameter has no specific type, // its type is unknown during the compilation // Variable Param1 will be typed with the type of the value passed in parameter // during the call to the procedure. // The MyVar variable will also have the same type // as the type of the Param1 variable known during the execution.
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 | unsigned integer on 1 byte | int | unsigned integer on 2 bytes | int | unsigned integer on 4 bytes | unsigned integer on 4 bytes | unsigned integer on 8 bytes | unsigned integer on 8 bytes | 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 on N | string (Ansi or Unicode) | Ansi string | Ansi string | Ansi string on N | Ansi string | Unicode string | Unicode string | Unicode string on N | Unicode string | ASCIIZ string on N | Ansi string | Fixed string on N | Ansi string | Pascal string on 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:
let <Variable> <- <Value>
where: - <Variable> corresponds to the name of variable to declare.
- <Value> corresponds to the value assigned to the variable to declare.
Versions 19 and later2. Multiple inference:
let (<Variable 1>, ..., <Variable N>) <- (<Value 1>, ..., <Value N>)
where: - <Variable 1> ... <Variable N> correspond to the names of variables to declare.
- <Value 1> ... <Value N> correspond to the values assigned to each variable to declare.
New in version 192. Multiple inference:
let (<Variable 1>, ..., <Variable N>) <- (<Value 1>, ..., <Value N>)
where: - <Variable 1> ... <Variable N> correspond to the names of variables to declare.
- <Value 1> ... <Value N> correspond to the values assigned to each variable to declare.
2. Multiple inference:
let (<Variable 1>, ..., <Variable N>) <- (<Value 1>, ..., <Value N>)
where: - <Variable 1> ... <Variable N> correspond to the names of variables to declare.
- <Value 1> ... <Value N> correspond to the values assigned to each variable to declare.
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, ...
During an assignment by reference, the value of reference variable is not copied into 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:
clMyClient is cClient // cClient class, clMyClient object let clClient <- clMyClient // class type, clClient points to clMyClient object
arrPrice is array of 5 currencies arrPrice[1] = 500.00 arrPrice[2] = 250
let tPrice <- arrPrice // array type, tPrice points to the arrPrice array
This page is also available for…
|
|
|
| |
| Click [Add] to post a comment |
|
| |
|
| |
| |
| |
| |
| |
| |
| | |
| |