Skip to content

Commit

Permalink
Update multi-stage example to reference latest example from Macros se…
Browse files Browse the repository at this point in the history
…ction

Current Example is based on obsolete content of macros-spec.md (which was updated in commit d8c9714) . This small change brings in the updated content here as well.
  • Loading branch information
ozenzin authored Dec 18, 2024
1 parent 80e09f7 commit 95741a2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/_docs/reference/metaprogramming/staging.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ import scala.quoted.*
// make available the necessary compiler for runtime code generation
given staging.Compiler = staging.Compiler.make(getClass.getClassLoader)

val f: Array[Int] => Int = staging.run {
val stagedSum: Expr[Array[Int] => Int] =
'{ (arr: Array[Int]) => ${sum('arr)}}
println(stagedSum.show) // Prints "(arr: Array[Int]) => { var sum = 0; ... }"
stagedSum
def power3: Double => Double = staging.run {
val stagedPower3: Expr[Double => Double] =
'{ (x: Double) => ${ unrolledPowerCode('x, 3) } }
println(stagedPower3.show) // Prints "((x: scala.Double) => x.*(x.*(x)))"
stagedPower3
}

f.apply(Array(1, 2, 3)) // Returns 6
power3.apply(2.0) // Returns 8.0
```

0 comments on commit 95741a2

Please sign in to comment.