Skip to content

Commit

Permalink
Mention shorthand syntax for labels
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons authored and lpil committed Dec 22, 2024
1 parent f86af8a commit 1495c29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ pub fn main() {

// Using the labels in a different order
io.debug(calculate(1, multiply: 3, add: 2))

// You may have some local variables declared
let multiply = 3
let add = 2

// You can specify the variables by name when calling the function
io.debug(calculate(1, add: add, multiply: multiply))

// Or use shorthand syntax, if the variable names match the names of the
// labelled arguments
io.debug(calculate(1, add:, multiply:))
}

fn calculate(value: Int, add addend: Int, multiply multiplier: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
Labels are optional when calling a function, it is up to the programmer to
decide what is clearest in their code.
</p>


<p>
Additionally, when local variables have the same name as the labelled
argument, the variable name can be omitted when calling the function. This is
known as shorthand syntax for labels.
</p>

0 comments on commit 1495c29

Please sign in to comment.