Revert "Add a section about constants in patterns"

This reverts commit ed27885391b4ed686dc615872fbff77f8122a358.
This commit is contained in:
Richard Feldman 2022-08-15 22:25:07 -04:00
parent 77d9cef014
commit 9ecc304d25
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B

View file

@ -377,43 +377,18 @@ when color is
Green | Red | Yellow -> 4 # only gets run if totalColors < 3
```
This gives you a way to use local variables in patterns:
This gives you a way to use constants in patterns:
```rust
\min, max ->
when number is
0 -> "zero"
1 -> "one"
v if v == min -> "min"
v if v == max -> "max"
_ -> "other"
```
You can also use constants in pattern matches by fully-qualifying them:
```rust
when number is
0 -> "zero"
1 -> "one"
Num.pi -> "pi"
_ -> "other"
```
In Roc, you can also write `Foo.bar` inside the `Foo` module itself (and it even works for
unexposed things in the current module), which gives you a way to refer to top-level constants
in the same module.
So so the following code would work as expected, assuming it's written at the top level of
a module named `Foo`:
```rust
constant = 42
pi = 3.14
e = 2.72
when number is
0 -> "zero"
1 -> "one"
Foo.constant -> "constant"
_ -> "other"
v if v == pi -> "pi"
v if v == e -> "e"
_ -> ""
```
## Custom Types