Let declarations
Table of Contents
The let keyword allows you to declare names, both regular declartions and
function declarations. All names declared with let are available in the
top-level scope of the pint° program.
let declarations are always immutable, and thus cannot be redefined.
Regular let declarations #
A regular let declaration has the syntax let a = b, where a is a name and
b a expression which evaluated value will be assigned to a. The declared
identifiers can then be referred by other let declarations or in function calls.
Here are some examples:
| |
Function let declarations #
By appending a parameter to a let declaration identifier, it is converted to a function let declaration.
| |
A function has to have exactly one parameter, and it has to be a struct. You can emulate parameterless functions by using the unit.
let receiveNoParameter () =
print "No parameters"
let receiveSingleParameter (:param String) =
print "Single parameter"
let receiveMultipleParameters (:param1 String, :param2 int) =
print "Multiple parameters"Identifiers #
As we are talking about name declarations, this may be a good place to define what are valid or invalid identifiers in pint°.
For interoperability reasons, pint° chose to follow Dart’s identifier rules, so:
- Identifiers can have all regular ASCII letters (no diacritics), numbers,
_and$.; - Identifiers can’t start with a number.
Thus, those are some example of valid identifiers:
myVariable_privateVartotalAmountcalculate$umUserNameMAX_VALUEisValid123
And some invalid identifiers:
123start(cannot start with a digit)my-var(hyphens are not allowed)my/function(operators can’t be used)