Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
feat: underscores as parameter names in receivers (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
novusnota authored Jul 24, 2024
1 parent 4974922 commit b4cc87f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pages/book/contracts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ contract HelloWorld {
}
```

Naming a parameter of the receiver function with an underscore `_{:tact}` makes its value considered unused and discarded. This is useful when you don't need to inspect the message received and you only want it to convey a specific opcode:

```tact
message(42) UniverseCalls {}
contract Example {
receive(_: UniverseCalls) {
// Got a Message with opcode 42
}
}
```

### Internal functions

These functions behave similarly to private methods in popular object-oriented languages — they're internal to contracts and can be called by prefixing them with a special [identifier `self{:tact}`](#field-access). That's why internal functions can sometimes be referred to as "contract methods".
Expand Down
12 changes: 12 additions & 0 deletions pages/book/receive.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ contract MyContract {
}
}
```

Naming a parameter of the receiver function with an underscore `_{:tact}` makes its value considered unused and discarded. This is useful when you don't need to inspect the message received and you only want it to convey a specific opcode:

```tact
message(42) UniverseCalls {}
contract Example {
receive(_: UniverseCalls) {
// Got a Message with opcode 42
}
}
```

0 comments on commit b4cc87f

Please sign in to comment.