@@ -311,6 +311,15 @@ trait Reflection { reflection =>
311
311
def apply (symbol : Symbol , rhs : Option [Term ]): ValDef
312
312
def copy (original : Tree )(name : String , tpt : TypeTree , rhs : Option [Term ]): ValDef
313
313
def unapply (vdef : ValDef ): Option [(String , TypeTree , Option [Term ])]
314
+
315
+ /** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }` */
316
+ def let (name : String , rhs : Term )(body : Ident => Term ): Term
317
+
318
+ /** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }` */
319
+ def let (rhs : Term )(body : Ident => Term ): Term = let(" x" , rhs)(body)
320
+
321
+ /** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }` */
322
+ def let (terms : List [Term ])(body : List [Ident ] => Term ): Term
314
323
}
315
324
316
325
given ValDefMethods as ValDefMethods = ValDefMethodsImpl
@@ -3603,22 +3612,4 @@ trait Reflection { reflection =>
3603
3612
3604
3613
end TreeMap
3605
3614
3606
- // TODO: extract from Reflection
3607
-
3608
- /** Bind the `rhs` to a `val` and use it in `body` */
3609
- def let (rhs : Term )(body : Ident => Term ): Term = {
3610
- val sym = Symbol .newVal(Symbol .currentOwner, " x" , rhs.tpe.widen, Flags .EmptyFlags , Symbol .noSymbol)
3611
- Block (List (ValDef (sym, Some (rhs))), body(Ref (sym).asInstanceOf [Ident ]))
3612
- }
3613
-
3614
- /** Bind the given `terms` to names and use them in the `body` */
3615
- def lets (terms : List [Term ])(body : List [Term ] => Term ): Term = {
3616
- def rec (xs : List [Term ], acc : List [Term ]): Term = xs match {
3617
- case Nil => body(acc)
3618
- case x :: xs => let(x) { (x : Term ) => rec(xs, x :: acc) }
3619
- }
3620
- rec(terms, Nil )
3621
- }
3622
-
3623
-
3624
3615
}
0 commit comments