You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cpp2/declarations.md
+27-15Lines changed: 27 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -6,35 +6,44 @@ All Cpp2 declarations are written as **"_name_ `:` _kind_ `=` _statement_"**.
6
6
7
7
- The `:` is pronounced **"is a."**
8
8
9
-
- The `=` is pronounced **"defined as."**
9
+
- The `=` is pronounced **"defined as."** For the definition of something that will always have the same value, write `==`.
10
10
11
11
- The _statement_ is typically an expression statement (e.g., `#!cpp a + b();`) or a compound statement (e.g., `#!cpp { /*...*/ return c(d) / e; }`).
12
12
13
13
- Various parts of the syntax allow a `_` "don't care" wildcard or can be omitted entirely to accept a default (e.g., `#!cpp x: int = 0;` can be equivalently written `#!cpp x: _ = 0;` or `#!cpp x := 0;` both of which deduce the type).
14
14
15
-
> Note: When the type is omitted, whitespace does not matter, and writing `#!cpp x: = 0;` or `#!cpp x : = 0;` or `#!cpp x := 0;` or other whitespace is just a stylistic choice. This documentation's style uses the last one, except when there are multiple adjacent declaration lines this style lines up their `:` and `=`.
16
-
17
-
> Note: The only variation to the above is that 'constexpr' functions are written with `==` instead of `=` (e.g., `#!cpp square: (i: int) == i * i;`).
15
+
> Notes:
16
+
>
17
+
> - When the type is omitted, whitespace does not matter, and writing `#!cpp x: = 0;` or `#!cpp x : = 0;` or `#!cpp x := 0;` or other whitespace is just a stylistic choice. This documentation's style uses the last one, except when there are multiple adjacent declaration lines this style lines up their `:` and `=`.
18
+
>
19
+
> -`==` stresses that this name will always have the given value, to express [aliases](./aliases.md) and side-effect-free 'constexpr' functions (e.g., `#!cpp square: (i: int) == i * i;`).
// calc_next_year is a function defined as always returning the same
75
+
// value for the same input (i.e., 'constexpr', side effect-free)
76
+
calc_next_year: (year: i32) -> i32 == year + 1;
65
77
}
66
78
```
67
79
68
-
> Note: `@enum` is a metafunction, which provides an easy way to opt into a group of defaults, constraints, and generated functions. For details, see [`@enum`, `@flag_enum`](metafunctions.md#enum-flag_enum)
80
+
> Note: `@enum` is a metafunction, which provides an easy way to opt into a group of defaults, constraints, and generated functions. For details, see [`@enum`](metafunctions.md#enum).
0 commit comments