Skip to content

typo: Fix "unkown" to "unknown" #2045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions _overviews/scala3-macros/tutorial/inline.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ x2 * 1.0
In contrast, let us imagine we do not know the value of `n`:

```scala
power(2, unkownNumber)
power(2, unknownNumber)
```
Driven by the inline annotation on the parameter, the compiler will try to unroll the recursion.
But without any success, since the parameter is not statically known.
Expand All @@ -297,22 +297,22 @@ But without any success, since the parameter is not statically known.
```scala
// first inlines as
val x = 2
if (unkownNumber == 0) 1.0
else if (unkownNumber % 2 == 1) x * power(x, unkownNumber - 1)
else power(x * x, unkownNumber / 2)
if (unknownNumber == 0) 1.0
else if (unknownNumber % 2 == 1) x * power(x, unknownNumber - 1)
else power(x * x, unknownNumber / 2)
// then inlined as
val x = 2
if (unkownNumber == 0) 1.0
else if (unkownNumber % 2 == 1) x * {
if (unkownNumber - 1 == 0) 1.0
else if ((unkownNumber - 1) % 2 == 1) x2 * power(x2, unkownNumber - 1 - 1)
else power(x2 * x2, (unkownNumber - 1) / 2)
if (unknownNumber == 0) 1.0
else if (unknownNumber % 2 == 1) x * {
if (unknownNumber - 1 == 0) 1.0
else if ((unknownNumber - 1) % 2 == 1) x2 * power(x2, unknownNumber - 1 - 1)
else power(x2 * x2, (unknownNumber - 1) / 2)
}
else {
val x2 = x * x
if (unkownNumber / 2 == 0) 1.0
else if ((unkownNumber / 2) % 2 == 1) x2 * power(x2, unkownNumber / 2 - 1)
else power(x2 * x2, unkownNumber / 2 / 2)
if (unknownNumber / 2 == 0) 1.0
else if ((unknownNumber / 2) % 2 == 1) x2 * power(x2, unknownNumber / 2 - 1)
else power(x2 * x2, unknownNumber / 2 / 2)
}
// Oops this will never finish compiling
...
Expand All @@ -331,7 +331,7 @@ inline def power(x: Double, inline n: Int): Double =

```scala
power(2, 2) // Ok
power(2, unkownNumber) // error
power(2, unknownNumber) // error
```

We will come back to this example later and see how we can get more control on how code is generated.
Expand Down