Skip to content

Commit

Permalink
chore: reflect removal of ! from certain mutating function names (#185
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sockmaster27 authored Nov 21, 2024
1 parent 5969bc9 commit c39a8ac
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion src/identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions src/mutable-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```
Expand All @@ -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)
}
```
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/regions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
```
Expand All @@ -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)
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```

Expand Down

0 comments on commit c39a8ac

Please sign in to comment.