Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Commit 96d3217

Browse files
committed
add short form method and operation modificator
1 parent e260cce commit 96d3217

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

book/tutor/methods.md

+29
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,34 @@ Out.println("Named Product: " + namedProduct.name + ", " + namedProduct.price);
115115

116116
In this example, `Product` has both a default constructor and a parameterized constructor.
117117

118+
## Short Form Method Declaration
119+
120+
Vein also supports a short form for method declarations, similar to the arrow functions in C#.
121+
122+
### Syntax
123+
124+
```vein
125+
methodName(parameters): returnType |> expression;
126+
```
127+
128+
### Example
129+
130+
```vein
131+
class Example {
132+
test(): i32 |> 1;
133+
134+
add(a: i32, b: i32): i32 |> a + b;
135+
}
136+
137+
auto example = Example();
138+
Out.println(example.test()); // Output: 1
139+
Out.println(example.add(4, 3)); // Output: 7
140+
```
141+
142+
In this example:
143+
- `test` is a method that returns `1` using the short form declaration.
144+
- `add` is a method that returns the sum of `a` and `b` using the short form declaration.
145+
118146
## Operator Overloading
119147

120148
Operator overloading allows you to define custom behavior for operators when they are applied to instances of your classes. This can make your classes more intuitive to use.
@@ -177,6 +205,7 @@ Access modifiers control the visibility and accessibility of classes, methods, a
177205
- `abstract`: The member has no implementation in the base class and must be overridden in derived classes.
178206
- `async`: The member supports asynchronous operations.
179207
- `global`: Applicable only to type aliases, making them visible in all modules.
208+
- `operation`: Applicable only to quantum operation functions.
180209

181210
### Example of Access Modifiers
182211

0 commit comments

Comments
 (0)