From c39a8ac7219eb9f021a29aa2215bce813ef49c1b Mon Sep 17 00:00:00 2001 From: Holger Dal Mogensen <61235930+sockmaster27@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:51:46 +0100 Subject: [PATCH] chore: reflect removal of `!` from certain mutating function names (#185) --- src/arrays.md | 4 ++-- src/identifiers.md | 2 +- src/introduction.md | 2 +- src/mutable-collections.md | 18 +++++++++--------- src/regions.md | 10 +++++----- src/structs.md | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/arrays.md b/src/arrays.md index 615a4e9..9fcb714 100644 --- a/src/arrays.md +++ b/src/arrays.md @@ -172,11 +172,11 @@ which prints `3` when run. > **Note**: We advise against indexed-based iteration through arrays. Instead, > we recommend to use functions such as `Array.count`, `Array.forEach`, and -> `Array.transform!`. +> `Array.transform`. ### Additional Array Operations The `Array` module offers an extensive collection of functions for working with arrays. For example, `Array.append`, `Array.copyOfRange`, `Array.findLeft`, -`Array.findRight`, `Array.sortWith!`, and `Array.sortBy!` to name a few. In +`Array.findRight`, `Array.sortWith`, and `Array.sortBy` to name a few. In total, the module offers more than 100 functions ready for use. diff --git a/src/identifiers.md b/src/identifiers.md index 26a5e1f..b415013 100644 --- a/src/identifiers.md +++ b/src/identifiers.md @@ -5,7 +5,7 @@ Flix has several types of identifiers: * **Uppercase name:** An identifier that starts with an uppercase letter followed by any number of uppercase and lowercase letters, underscore, and exclamation mark (`A`…`Z`, `a`…`z`, `_`, `!`). * e.g. `String`, `ALL_UPPER`, `Shriek!` * Can be used to name: namespaces, annotations, traits, effects, predicates (within datalog), tags (within enums), types -* **Lowercase name:** An identifier that starts with aa lowercase letter followed by any number of uppercase and lowercase letters, underscore, and exclamation mark (`A`…`Z`, `a`…`z`, `_`, `!`). +* **Lowercase name:** An identifier that starts with a lowercase letter followed by any number of uppercase and lowercase letters, underscore, and exclamation mark (`A`…`Z`, `a`…`z`, `_`, `!`). * e.g. `anIdentifier`, `x`, `this_and_that` * Can be used to name: annotations, attributes (within datalog), functions, labels (within records), variables * **Greek name:** An identifier consisting of any combination of letters from the Greek alphabet (the unicode range U+0370 to U+03FF). diff --git a/src/introduction.md b/src/introduction.md index cb409b1..9d75dc9 100644 --- a/src/introduction.md +++ b/src/introduction.md @@ -97,7 +97,7 @@ def deduplicate(l: List[a]): List[a] with Order[a] = if (MutSet.memberOf(x, s)) false // `x` has already been seen. else { - MutSet.add!(x, s); + MutSet.add(x, s); true } }, l) diff --git a/src/mutable-collections.md b/src/mutable-collections.md index eef11cb..9a51b42 100644 --- a/src/mutable-collections.md +++ b/src/mutable-collections.md @@ -19,9 +19,9 @@ Here is an example of how to use `MutList[t]`: def main(): Unit \ IO = region rc { let fruits = MutList.empty(rc); - MutList.push!("Apple", fruits); - MutList.push!("Pear", fruits); - MutList.push!("Mango", fruits); + MutList.push("Apple", fruits); + MutList.push("Pear", fruits); + MutList.push("Mango", fruits); MutList.forEach(println, fruits) } ``` @@ -37,9 +37,9 @@ def main(): Unit \ IO = region rc { let fruits = MutList.empty(rc) !> - MutList.push!("Apple") !> - MutList.push!("Pear") !> - MutList.push!("Mango"); + MutList.push("Apple") !> + MutList.push("Pear") !> + MutList.push("Mango"); MutList.forEach(println, fruits) } ``` @@ -55,9 +55,9 @@ def main(): Unit \ IO = def sweetFruits(rc: Region[r]): MutList[String, r] \ r = MutList.empty(rc) !> - MutList.push!("Apple") !> - MutList.push!("Pear") !> - MutList.push!("Mango") + MutList.push("Apple") !> + MutList.push("Pear") !> + MutList.push("Mango") def printFruits(fruits: MutList[String, r]): Unit \ {r, IO} = MutList.forEach(println, fruits) diff --git a/src/regions.md b/src/regions.md index a9fde08..712a8fb 100644 --- a/src/regions.md +++ b/src/regions.md @@ -22,14 +22,14 @@ We can use regions to implement a pure `sort` function that internally uses muta def sort(l: List[a]): List[a] with Order[a] = region rc { let arr = List.toArray(rc, l); - Array.sort!(arr); + Array.sort(arr); Array.toList(arr) } ``` Here we introduce a region named `rc`. We use the function `List.toArray` to convert the list `l` to a mutable array `arr` associated with the region `rc`. -We then sort `arr` using `Array.sort!` which uses an efficient in-place sorting +We then sort `arr` using `Array.sort` which uses an efficient in-place sorting algorithm. Finally, we convert the sorted array back to a list and return it. The `sort` function is pure, even though it internally uses mutation. @@ -40,8 +40,8 @@ is pure but internally uses a mutable `StringBuilder`: def toString(l: List[a]): String with ToString[a] = region rc { let sb = StringBuilder.empty(rc); - List.forEach(x -> StringBuilder.appendString!("${x} :: ", sb), l); - StringBuilder.appendString!("Nil", sb); + List.forEach(x -> StringBuilder.appendString("${x} :: ", sb), l); + StringBuilder.appendString("Nil", sb); StringBuilder.toString(sb) } // scope of rc ends, the entire expression is pure. ``` @@ -57,7 +57,7 @@ efficiently. For example, here is a fast implementation of `List.flatMap`: def flatMap(f: a -> List[b] \ ef, l: List[a]): List[b] \ ef = region rc { let ml = MutList.empty(rc); - l |> List.forEach(x -> MutList.append!(f(x), ml)); + l |> List.forEach(x -> MutList.append(f(x), ml)); MutList.toList(ml) } ``` diff --git a/src/structs.md b/src/structs.md index 2413c85..3322e72 100644 --- a/src/structs.md +++ b/src/structs.md @@ -247,7 +247,7 @@ However, since a `MutList` can be changed, we can write: ```flix mod Book { pub def addAuthor(a: String, b: Book[r]): Unit \ r = - MutList.push!(a, b->authors) + MutList.push(a, b->authors) } ```