suffix unary operators (++, --) working as intended
This commit is contained in:
35
README.md
35
README.md
@@ -86,6 +86,21 @@ get translated to during compilation. Comparisons and operations on strings are
|
||||
and quite buggy, but you are free to use string literals for prints or simple variable declarations with no issues.
|
||||
Variables cannot be declared with type `void`.
|
||||
|
||||
The `string` type actually behaves similarly to how a class would. While using the variable directly
|
||||
gives you access to the actual string (which in C corresponds to the `char*`), you can use `.len` to
|
||||
get the length of the string. Note that `len` is an immutable member, so you cannot maually set it.
|
||||
|
||||
```
|
||||
let mystring string = "this is my string";
|
||||
print(mystring, mystring.len)
|
||||
```
|
||||
|
||||
produces this output:
|
||||
|
||||
```
|
||||
this is my string 17
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Functions
|
||||
@@ -133,6 +148,26 @@ let myuser User = User{17, "uan", false}
|
||||
Class types can be used anywhere primitive types can, such as function arguments
|
||||
or other classes' members.
|
||||
|
||||
Class members can be defined as immutable with the `immutable` keyword before the member name.
|
||||
This is checked at compile time and prevents that member's value to be changed after instantiation.
|
||||
For example, this code would trigger a parse error, `as u.id = 0` attempts to change an immutable
|
||||
member's value.
|
||||
|
||||
```
|
||||
class User {
|
||||
age int
|
||||
name string
|
||||
mail_verified bool
|
||||
immutable id int
|
||||
}
|
||||
|
||||
fn change_values(u User) {
|
||||
u.age = 10;
|
||||
u.name = "new name";
|
||||
u.id = 0;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Print
|
||||
|
||||
Reference in New Issue
Block a user