From 1495c29c9e6efa6249e83ea4e51b9e014e48e35e Mon Sep 17 00:00:00 2001
From: "Joseph T. Lyons"
Date: Sat, 7 Dec 2024 01:42:29 -0500
Subject: [PATCH] Mention shorthand syntax for labels
---
.../lesson08_labelled_arguments/code.gleam | 11 +++++++++++
.../lesson08_labelled_arguments/en.html | 7 +++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/content/chapter1_functions/lesson08_labelled_arguments/code.gleam b/src/content/chapter1_functions/lesson08_labelled_arguments/code.gleam
index 25bb8c1..becdf7f 100644
--- a/src/content/chapter1_functions/lesson08_labelled_arguments/code.gleam
+++ b/src/content/chapter1_functions/lesson08_labelled_arguments/code.gleam
@@ -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) {
diff --git a/src/content/chapter1_functions/lesson08_labelled_arguments/en.html b/src/content/chapter1_functions/lesson08_labelled_arguments/en.html
index b1d771c..49d3cf8 100644
--- a/src/content/chapter1_functions/lesson08_labelled_arguments/en.html
+++ b/src/content/chapter1_functions/lesson08_labelled_arguments/en.html
@@ -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.
-
-
+
+ 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.
+