@@ -598,14 +598,45 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
598598 def copy (original : Tree )(name : String , tpt : TypeTree , rhs : Option [Term ]): ValDef
599599 def unapply (vdef : ValDef ): (String , TypeTree , Option [Term ])
600600
601- /** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }` */
601+ /** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }`
602+ *
603+ * Usage:
604+ * ```
605+ * ValDef.let(owner, "x", rhs1) { x =>
606+ * ValDef.let(x.symbol.owner, "y", rhs2) { y =>
607+ * // use `x` and `y`
608+ * }
609+ * }
610+ * ```
611+ * @syntax markdown
612+ */
602613 def let (owner : Symbol , name : String , rhs : Term )(body : Ref => Term ): Term
603614
604- /** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }` */
615+ /** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }`
616+ *
617+ * Usage:
618+ * ```
619+ * ValDef.let(owner, rhs1) { x =>
620+ * ValDef.let(owner, rhs2) { y =>
621+ * // use `x` and `y`
622+ * }
623+ * }
624+ * ```
625+ * @syntax markdown
626+ */
605627 def let (owner : Symbol , rhs : Term )(body : Ref => Term ): Term =
606628 let(owner, " x" , rhs)(body)
607629
608- /** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }` */
630+ /** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }`
631+ *
632+ * Usage:
633+ * ```
634+ * ValDef.let(owner, rhsList) { xs =>
635+ * ...
636+ * }
637+ * ```
638+ * @syntax markdown
639+ */
609640 def let (owner : Symbol , terms : List [Term ])(body : List [Ref ] => Term ): Term
610641 }
611642
@@ -1318,6 +1349,28 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
13181349 * ```scala sc:nocompile
13191350 * Block((DefDef(_, _, params :: Nil, _, Some(rhsFn(meth, paramRefs)))) :: Nil, Closure(meth, _))
13201351 * ```
1352+ *
1353+ * Usage:
1354+ * ```
1355+ * val mtpe = MethodType(List("arg1"))(_ => List(TypeRepr.of[Int]), _ => TypeRepr.of[Int])
1356+ * Lambda(owner, mtpe, {
1357+ * case (methSym, List(arg1: Term)) =>
1358+ * ValDef.let(methSym, f(arg1)) { ... }
1359+ * }
1360+ * )
1361+ * ```
1362+ *
1363+ * Usage with quotes:
1364+ * ```
1365+ * val mtpe = MethodType(List("arg1"))(_ => List(TypeRepr.of[Int]), _ => TypeRepr.of[Int])
1366+ * Lambda(owner, mtpe, {
1367+ * case (methSym, List(arg1: Term)) =>
1368+ * given Quotes = methSym.asQuotes
1369+ * '{ ... }
1370+ * }
1371+ * )
1372+ * ```
1373+ *
13211374 * @param owner: owner of the generated `meth` symbol
13221375 * @param tpe: Type of the definition
13231376 * @param rhsFn: Function that receives the `meth` symbol and the a list of references to the `params`
@@ -3783,6 +3836,27 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
37833836
37843837 /** Case class or case object children of a sealed trait or cases of an `enum`. */
37853838 def children : List [Symbol ]
3839+
3840+ /** Returns a nested quote with this symbol as splice owner (`Symbol.spliceOwner`).
3841+ *
3842+ * Changes the owner under which the definition in a quote are created.
3843+ *
3844+ * Usage:
3845+ * ```scala
3846+ * new TreeMap:
3847+ * override def transformTerm(tree: Term)(owner: Symbol): Term =
3848+ * tree match
3849+ * case tree: Ident =>
3850+ * given Quotes = owner.asQuotes
3851+ * // Definitions contained in the quote will be owned by `owner`.
3852+ * // No need to use `changeOwner` in this case.
3853+ * '{ val x = ???; x }.asTerm
3854+ * ```
3855+ * @syntax markdown
3856+ */
3857+ @ experimental
3858+ def asQuotes : Nested
3859+
37863860 end extension
37873861 }
37883862
0 commit comments