Types
Types are optional in Lesma, you can choose whether you specify them or not. Unspecified variable types are inferred at compile time from the value of the assignment.
Operations between different types will either be casted to the larger type if the two types are compatible, or give an error otherwise. Two types are compatible if they are different sizes of the same group type (such as ints or floating points).
The type must be either a user-defined type, enum, class, or a built-in type.
Warning
Types that are not specified are inferred, this is fundamentally different in comparison to dynamic types!
Built-in Types
Any
Any types can receive any kind of value, so it can receive any kind of value at any moment.
1 2 |
|
Warning
Any type is not implemented yet!
Int
There are multiple types of ints available based on width and signed/unsigned. They can get a minimum of 8 bits width and a maximum of 128. If the width is not specified, it's by default 64.
- Signed: int
, int8
, int16
, int32
, int64
, int128
- Unsigned: uint
, uint8
, uint16
, uint32
, uint64
, uint128
1 2 3 4 |
|
Info
In Lesma, int and uint are by default 64 bits wide, and they will enlarge by themselves to 128 bits wide if needed. This is not the default behaviour if you specify the size yourself!
Float
Float is floating-point real number.
1 |
|
Double
Double is double-precision floating-point real number.
1 2 |
|
Str
Str is Lesma's implementation of strings/char lists. All Lesma strings support UTF-8.
1 2 3 |
|
Bool
Bools occupy only 1 bit, and can be either true
or false
.
1 |
|
List
Lists are mutable by default, are declared using square paranthesis, have dynamic size, start from 0, and the members are accessed using the their index around square paranthesis. The element can be declared between <>
. If the type is omitted, the list will have the type of the elements contained.
1 2 3 |
|
Tuple
Tuples are like lists, but immutable, and declared using round paranthesis.
The element type can be declared between <>
. If the type is omitted, the list will have the type of the elements contained.
1 2 3 |
|
Dict
Dictionaries are lists of key-value pairs (similar to hashmaps), and they're mutable
1 2 |
|
Warning
Dicts are not yet implemented!
Range
Ranges are similar to Python's ranges, defined using start..end
kind of syntax, and they're especially used for loops
1 2 |
|
Warning
Ranges can not currently be assigned to variables
Func
Lesma supports first class functions, meaning that variables can be assigned functions, and the type func is meant to annotate the type of the function.
Parameter types are included between <>
separated by comma ,
, and the return type with arrow ->
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Void
Void is used only for function return types and are used to illustrate that the function does not return a value. If the return type of a function is omitted, void will be used by default.
1 2 3 4 5 |
|
Type Operations
Is
Is
binary operator checks if the left operand's type matches the right operand and returns a bool as a result
1 2 |
|
As
As
binary operator casts the left operand to the right operand type and returns the casted value
1 2 |
|