Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

crStiv
Copy link

@crStiv crStiv commented Mar 3, 2025

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:

  • Clear explanation of the underscore parameter feature
  • Practical example showing its usage
  • Follows the existing documentation style and formatting

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Copy link
Contributor

github-actions bot commented Mar 3, 2025

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.

Copy link
Member

@TomAFrench TomAFrench left a 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

Comment on lines 40 to 43
fn foo(_ : Field, y : Field) {
// Only using y parameter
y + 1
}
Copy link
Member

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:
Copy link
Member

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.

@crStiv
Copy link
Author

crStiv commented Mar 3, 2025

like this? or did I not understand you right?

@TomAFrench

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document support of _ as function parameters
2 participants