@@ -98,9 +98,9 @@ scala -with-compiler -classpath out Test
9898## Example
9999
100100Now 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
102102the 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
104104expression at runtime. Within the scope of ` staging.run ` we can also invoke ` show ` on an expression
105105to 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
111111given 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