init snippets

This commit is contained in:
jilen 2024-11-02 20:34:57 +08:00
commit cc9255ae51
5 changed files with 137 additions and 0 deletions

21
std/macro.scala Normal file
View file

@ -0,0 +1,21 @@
//> using scala 3.4.0
import scala.quoted.*
inline def printTree[A](inline x: A) = ${printTreeImpl[A]('x)}
private def printTreeImpl[A](x: Expr[A])(using Quotes) = {
import quotes.reflect.*
def print0(t: Term): Unit = {
t match {
case Inlined(_, _, n) =>
print0(n)
case Lambda(vals, body) =>
println(s"Lambda body ${body}")
case o =>
println(s"Lambda body ${o}")
}
}
print0(x.asTerm)
'{()}
}

3
std/newInstance.scala Normal file
View file

@ -0,0 +1,3 @@
//> using scala 3.3.4