@@ -607,14 +607,45 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
607607 def copy (original : Tree )(name : String , tpt : TypeTree , rhs : Option [Term ]): ValDef
608608 def unapply (vdef : ValDef ): (String , TypeTree , Option [Term ])
609609
610- /** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }` */
610+ /** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }`
611+ *
612+ * Usage:
613+ * ```
614+ * ValDef.let(owner, "x", rhs1) { x =>
615+ * ValDef.let(x.symbol.owner, "y", rhs2) { y =>
616+ * // use `x` and `y`
617+ * }
618+ * }
619+ * ```
620+ * @syntax markdown
621+ */
611622 def let (owner : Symbol , name : String , rhs : Term )(body : Ref => Term ): Term
612623
613- /** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }` */
624+ /** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }`
625+ *
626+ * Usage:
627+ * ```
628+ * ValDef.let(owner, rhs1) { x =>
629+ * ValDef.let(owner, rhs2) { y =>
630+ * // use `x` and `y`
631+ * }
632+ * }
633+ * ```
634+ * @syntax markdown
635+ */
614636 def let (owner : Symbol , rhs : Term )(body : Ref => Term ): Term =
615637 let(owner, " x" , rhs)(body)
616638
617- /** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }` */
639+ /** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }`
640+ *
641+ * Usage:
642+ * ```
643+ * ValDef.let(owner, rhsList) { xs =>
644+ * ...
645+ * }
646+ * ```
647+ * @syntax markdown
648+ */
618649 def let (owner : Symbol , terms : List [Term ])(body : List [Ref ] => Term ): Term
619650 }
620651
@@ -1327,6 +1358,28 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
13271358 * ```scala sc:nocompile
13281359 * Block((DefDef(_, _, params :: Nil, _, Some(rhsFn(meth, paramRefs)))) :: Nil, Closure(meth, _))
13291360 * ```
1361+ *
1362+ * Usage:
1363+ * ```
1364+ * val mtpe = MethodType(List("arg1"))(_ => List(TypeRepr.of[Int]), _ => TypeRepr.of[Int])
1365+ * Lambda(owner, mtpe, {
1366+ * case (methSym, List(arg1: Term)) =>
1367+ * ValDef.let(methSym, f(arg1)) { ... }
1368+ * }
1369+ * )
1370+ * ```
1371+ *
1372+ * Usage with quotes:
1373+ * ```
1374+ * val mtpe = MethodType(List("arg1"))(_ => List(TypeRepr.of[Int]), _ => TypeRepr.of[Int])
1375+ * Lambda(owner, mtpe, {
1376+ * case (methSym, List(arg1: Term)) =>
1377+ * given Quotes = methSym.asQuotes
1378+ * '{ ... }
1379+ * }
1380+ * )
1381+ * ```
1382+ *
13301383 * @param owner: owner of the generated `meth` symbol
13311384 * @param tpe: Type of the definition
13321385 * @param rhsFn: Function that receives the `meth` symbol and the a list of references to the `params`
@@ -3792,6 +3845,27 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
37923845
37933846 /** Case class or case object children of a sealed trait or cases of an `enum`. */
37943847 def children : List [Symbol ]
3848+
3849+ /** Returns a nested quote with this symbol as splice owner (`Symbol.spliceOwner`).
3850+ *
3851+ * Changes the owner under which the definition in a quote are created.
3852+ *
3853+ * Usage:
3854+ * ```scala
3855+ * new TreeMap:
3856+ * override def transformTerm(tree: Term)(owner: Symbol): Term =
3857+ * tree match
3858+ * case tree: Ident =>
3859+ * given Quotes = owner.asQuotes
3860+ * // Definitions contained in the quote will be owned by `owner`.
3861+ * // No need to use `changeOwner` in this case.
3862+ * '{ val x = ???; x }.asTerm
3863+ * ```
3864+ * @syntax markdown
3865+ */
3866+ @ experimental
3867+ def asQuotes : Nested
3868+
37953869 end extension
37963870 }
37973871
0 commit comments