Skip to content

Commit 95741a2

Browse files
authored
Update multi-stage example to reference latest example from Macros section
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.
1 parent 80e09f7 commit 95741a2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/_docs/reference/metaprogramming/staging.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ import scala.quoted.*
110110
// make available the necessary compiler for runtime code generation
111111
given staging.Compiler = staging.Compiler.make(getClass.getClassLoader)
112112

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

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

0 commit comments

Comments
 (0)