@@ -98,9 +98,9 @@ scala -with-compiler -classpath out Test
98
98
## Example
99
99
100
100
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
102
102
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
104
104
expression at runtime. Within the scope of ` staging.run ` we can also invoke ` show ` on an expression
105
105
to get a source-like representation of the expression.
106
106
@@ -110,12 +110,12 @@ import scala.quoted.*
110
110
// make available the necessary compiler for runtime code generation
111
111
given staging .Compiler = staging.Compiler .make(getClass.getClassLoader)
112
112
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
118
118
}
119
119
120
- f .apply(Array ( 1 , 2 , 3 )) // Returns 6
120
+ power3 .apply(2.0 ) // Returns 8.0
121
121
```
0 commit comments