-
Notifications
You must be signed in to change notification settings - Fork 250
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
docs: add underscore parameter documentation #7562
base: master
Are you sure you want to change the base?
Conversation
Thank you for your contribution to the Noir language. Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch. Thanks for your understanding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR. A couple of notes
docs/docs/noir/concepts/functions.md
Outdated
fn foo(_ : Field, y : Field) { | ||
// Only using y parameter | ||
y + 1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function isn't valid noir as it's returning a value while the return type of the function is ()
.
@@ -34,6 +34,15 @@ is pre-pended with a colon and the parameter type. Multiple parameters are separ | |||
fn foo(x : Field, y : Field){} | |||
``` | |||
|
|||
You can use an underscore `_` as a parameter name when you don't need to use the parameter in the function body. This is useful when you need to satisfy a function signature but don't need to use all the parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noir actually ignores any parameter with a leading underscore so _x
would also be accepted. This is preferred in general as it self-documents what the unused parameter is.
like this? or did I not understand you right? |
Description
Problem*
Resolves #6917
Summary*
Added documentation for the underscore
_
parameter feature in functions. This documents an existing feature where parameters can be marked with an underscore when they are not used in the function body, which is particularly useful for implementing traits or interfaces where not all parameters are needed.Additional Context
The documentation was added to the Functions concept guide, specifically in the parameters section. The addition includes:
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.