docs: add comparison table for mut vs ref parameters #9409
+18
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Added a structured comparison list explaining the key differences between
mutandreffunction parameters in the Parameters section. The comparison clarifies three critical aspects: how changes propagate to the caller, call syntax requirements, and the intended purpose of each modifier.Type of change
Please check one:
Why is this change needed?
The documentation previously explained
mutandrefparameters separately without a clear side-by-side comparison. While thevariables.adocpage provides better structure, thefunctions.adocpage lacked explicit comparison, making it harder for readers to understand when to use each modifier and what the practical differences are.The absence of a comparison table/list created a gap where developers had to piece together information from multiple paragraphs, potentially leading to confusion about:
mutparameters affect the caller (they don't)refparametersmut) and input/output parameters (ref)What was the behavior or documentation before?
The Parameters section explained
mutandrefmodifiers in separate paragraphs:mutwas described as creating a mutable variable that can be modified in the functionrefwas described as simulating a reference that affects the caller's valueHowever, there was no explicit comparison showing:
The only hint was the statement "These can be either
mutorref(not both)" without explaining why they're mutually exclusive or what makes them different.What is the behavior or documentation after?
The documentation now includes a structured comparison list with three key points:
mutchanges are local whilerefchanges affect the callermutuses regular expressions whilerefrequires therefkeyword with a mutable variablemut) from input/output parameters (ref)Additionally, a note clarifies that
refparameters are implicitly mutable and cannot be combined withmut, explaining the mutual exclusivity mentioned earlier.The format follows the same style used elsewhere in the documentation (e.g., the "Snapshots vs references" section in
snapshot-type.adoc).Related issue or discussion (if any)
Additional context
This change improves the documentation by providing a quick reference for developers choosing between
mutandrefparameters. The comparison format is consistent with other comparison sections in the Cairo documentation, maintaining stylistic consistency across the reference manual.The information was already present in
variables.adoc, but having it infunctions.adocas well improves discoverability since developers reading about function parameters will find the comparison in the same section without needing to cross-reference other pages.