docs: add comparison table for mut vs ref parameters
Summary
Added a structured comparison list explaining the key differences between mut and ref function 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:
- [ ] Bug fix (fixes incorrect behavior)
- [ ] New feature
- [ ] Performance improvement
- [x] Documentation change with concrete technical impact
- [ ] Style, wording, formatting, or typo-only change
⚠️ Note: To keep maintainer workload sustainable, we generally do not accept PRs that are only minor wording, grammar, formatting, or style changes. Such PRs may be closed without detailed review.
Why is this change needed?
The documentation previously explained mut and ref parameters separately without a clear side-by-side comparison. While the variables.adoc page provides better structure, the functions.adoc page 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:
- Whether changes to
mutparameters affect the caller (they don't) - The syntax requirements for calling functions with
refparameters - The semantic difference between local mutability (
mut) and input/output parameters (ref)
What was the behavior or documentation before?
The Parameters section explained mut and ref modifiers in separate paragraphs:
-
mutwas described as creating a mutable variable that can be modified in the function -
refwas described as simulating a reference that affects the caller's value
However, there was no explicit comparison showing:
- The difference in caller behavior
- The difference in call syntax
- The difference in intended use cases
The only hint was the statement "These can be either mut or ref (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:
-
Changes in caller - Explicitly states that
mutchanges are local whilerefchanges affect the caller -
Call syntax - Clarifies that
mutuses regular expressions whilerefrequires therefkeyword with a mutable variable -
Purpose - Distinguishes local mutability (
mut) from input/output parameters (ref)
Additionally, a note clarifies that ref parameters are implicitly mutable and cannot be combined with mut, 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 mut and ref parameters. 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 in functions.adoc as well improves discoverability since developers reading about function parameters will find the comparison in the same section without needing to cross-reference other pages.