File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
sbt-dotty/sbt-test/sbt-dotty/quoted-example-project/src/main/scala/hello Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -30,17 +30,17 @@ object Main {
3030 assert(Math .pow(3 , 4 ) == toTheFourth(3 ))
3131 }
3232
33- def stagedPower (n : Int ): Double => Double = {
33+ def stagedPower (n : Int ): Double => Double = run {
3434 // Code representing the labmda where the recursion is unrolled based on the value of n
3535 val code = ' { (x : Double ) => $ {powerCode(n, ' {x})}}
3636
3737 code.show
3838
3939 // Evaluate the contents of the code and return it's value
40- code.run
40+ code
4141 }
4242
43- def powerCode (n : Int , x : Expr [Double ]): Expr [Double ] =
43+ def powerCode (n : Int , x : Expr [Double ]) given QuoteContext : Expr [Double ] =
4444 if (n == 0 ) ' {1.0 }
4545 else if (n == 1 ) x
4646 else if (n < 0 ) throw new Exception (" Negative powers not implemented. Left as a small exercise. Dont be shy, try it out." )
You can’t perform that action at this time.
0 commit comments