Skip to content

Conversation

@aigerimu
Copy link
Contributor

closes #1619

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No documentation issues detected.

@aigerimu
Copy link
Contributor Author

/review

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clear Tolk functions doc. I’ve left a couple of suggestions in languages/tolk/syntax/functions-methods.mdx: please apply the inline suggestions.

Comment on lines 102 to 148
### Receiver and `self`

The type of `self` is determined by the receiver. All parameters after `self` must have explicit types. If the return type is omitted, it is inferred.

```tolk
fun Point.equalTo(self, r: Point) { // auto-infer `bool`
return self.x == r.x && self.y == r.y
}
```

### Methods for non-struct types

Methods are not limited to structures. They may be declared for any receiver type, unions, aliases, and primitives:

```tolk
fun int.one() {
return 1
}
fun int.negate(self) {
return -self
}
fun demo() {
return int.one().negate() // -1
}
```

All standard methods are declared this way: `fun cell.hash(self)`, etc.

The type of `self` is determined by the receiver.
All parameters after should have their types set.
The return type is inferred if omitted.
All standard methods are declared this way: `fun cell.hash(self)`.

```tolk
fun Point.equalTo(self, r: Point) { // auto-infer `bool`
return self.x == r.x && self.y == r.y
}
```
## Immutability of `self`

## `self` is immutable by default
In instance methods, `self` is immutable by default.

To allow modifications, declare `mutate self` explicitly.
For details, see [mutability](/languages/tolk/syntax/mutability).
To allow modifications, declare [`mutate self`](/languages/tolk/syntax/mutability) explicitly.

```tolk
// mind `mutate` — to allow modifications
fun Point.reset(mutate self) {
self.x = 0;
self.y = 0;
}
```

## `return self` makes a chainable method
### Returning `self` and method chaining

Returning `self` makes a method chainable. To enable chaining, declare the `return` type as `self`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Code font used in headings

The section headings “Receiver and self”, “Immutability of self”, and “Returning self and method chaining” still contain inline code formatting on self in the heading text. The internal style guide requires headings to avoid styling such as code font or quotes (outside narrow reference-page exceptions) to keep the table of contents consistent and easily scannable. Leaving self styled in headings makes the TOC visually noisy and inconsistent with other documentation. The code font can remain in the body text while the headings themselves use plain text, in line with Style rule — headings formatting.

Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!

Comment on lines +7 to 20
## Function declaration

- `fun f(<params>)` — a function
- `fun <receiver>.f(<params>)` — a method:
- `fun <receiver>.f(self, ...)` — an instance method
- `fun <receiver>.f(...)` — a static method (no `self`)
A function is declared using the `fun` keyword, followed by the function name and parameters:

All features are identical except for the receiver.
Most examples below use functions, but all concepts equally apply to methods.
```tolk
fun f(<params>)
```

### Parameter type

## Types for parameters are required
Each function parameter must have an explicit type.

```tolk
// invalid:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[HIGH] Placeholders not defined on first use in examples

The initial function declaration example introduces the placeholder <params> in fun f(<params>) without an accompanying definition explaining what <params> represents. Shortly below, the method declaration example uses <receiver> in fun <receiver>.f(<params>), and later the attributes list introduces <number> and <anything> in @method_id(<number>) and @custom(<anything>) without first defining them. The style guide requires that placeholders written in <ANGLE_CASE> notation be explicitly defined on first use so examples are unambiguous and safe to copy into real code. Without these definitions, readers must infer the meaning of each placeholder, which reduces clarity and can lead to misinterpretation of the examples, contrary to Style rule — placeholders in examples.

Please leave a reaction 👍/👎 to this suggestion to improve future reviews for everyone!

@novusnota novusnota self-assigned this Jan 5, 2026
@novusnota novusnota added this to the Epic: Jan 5 — 19 milestone Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tolk > Syntax details > Functions and methods]

3 participants