Skip to content

Add note about constexpr functions to declarations.md #988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/cpp2/declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All Cpp2 declarations are written as **"_name_ `:` _kind_ `=` _statement_"**.

> 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 `=`.

> Note: The only variation to the above is that 'constexpr' functions are written with `==` instead of `=` (e.g., `#!cpp square: (i: int) == i * i;`).
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the tersest lambda syntax can skip the = entirely. But I think for both, Herb might have not added them yet to the docs as they both have contentions in their current form. #714 for tersest lambda syntax, #959 for constexpr with ==.


## Examples

Expand Down Expand Up @@ -58,6 +59,9 @@ n: namespace

// color is an @enum type (see Note)
color: @enum type = { red; green; blue; }

// a constexpr function is defined with `==`
calc_next_year: (year: i32) -> i32 == { return year + 1; }
}
```

Expand Down