Skip to content

Commit 169f6a8

Browse files
ozenzintgodzik
authored andcommittedMar 13, 2025
Update Example referring to updated macros-spec.md
An example code in macros-spec.md was updated in commit d8c9714, but thisstaging.md is still referring the old code. This small change removes reference to old code. [Cherry-picked 669972b]
1 parent 23268da commit 169f6a8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
 

‎docs/_docs/reference/metaprogramming/staging.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ scala -with-compiler -classpath out Test
9898
## Example
9999

100100
Now take exactly the same example as in [Macros](./macros.md). Assume that we
101-
do not want to pass an array statically but generate code at run-time and pass
101+
do not want to pass a base double value statically but generate code at run-time and pass
102102
the value, also at run-time. Note, how we make a future-stage function of type
103-
`Expr[Array[Int] => Int]` in line 6 below. Using `staging.run { ... }` we can evaluate an
103+
`Expr[Double => Double]` in line 6 below. Using `staging.run { ... }` we can evaluate an
104104
expression at runtime. Within the scope of `staging.run` we can also invoke `show` on an expression
105105
to get a source-like representation of the expression.
106106

@@ -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+
val 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)
Failed to load comments.