scala-macros Questions
2
Solved
I am coding using scala3, leveraging programmatic structural types.
The structural types happen to mimic existing case classes:
their definition is pure boiler plate,
hence the temptation to craft ...
Pernas asked 23/11, 2022 at 15:42
1
Scala 3.3.0-RC2 has added MacroAnnotation but it has a ton of caveats. The main on is that "new definitions will not be visible from outside the macro expansion".
There are a lot of examp...
Gonocyte asked 13/4, 2023 at 2:39
1
how to generate a private parameterless constructor on a class (at compile time) when it annotated with @entity
annotation - in scala 3 macros
class entity extends scala.annotation.StaticAnnotation...
Scarabaeid asked 18/1, 2023 at 12:15
2
Solved
The following is a quote from Macros: the Plan for Scala 3 from more than 3 years ago:
For instance, one will be able to define a macro annotation @json that adds a JSON serializer to a type.
Any...
Enharmonic asked 31/5, 2021 at 9:13
3
Solved
I have the following code:
object Macros {
import scala.language.experimental.macros
import scala.reflect.macros.blackbox
def hello(): Unit = macro hello_impl
def hello_impl(c: blackbox.Con...
Ravi asked 13/1, 2015 at 10:16
3
Solved
Can I generate Scala code from a template (of sorts)?
I know how to do this in Racket/Scheme/Lisp, but not in Scala. Is this something Scala macros can do?
I want to have a code template where X ...
Prewar asked 15/10, 2019 at 18:38
1
Solved
I want to execute splice() for each argument of my varargs:
import scala.reflect.macros.blackbox
object LoggerMacro {
def log(context: blackbox.Context)
(message: context.Expr[String], arguments...
Stokowski asked 26/9, 2022 at 22:34
1
With Scala2 I could implement a macro and generate types using tq quasiquote syntax, for eg:
q"""
new Foo {
type Bar = ${tq"(..$params)"}
}
"""
I am able ...
Esma asked 26/9, 2022 at 10:24
1
Solved
I am trying to use the macros with quoted DSL for generating a class like this —
val name = ???
'{
final class ${name} {
def foo: String = ...
def bar: Int = ...
}
}
The idea is to generate a...
Birdsall asked 26/9, 2022 at 1:53
1
i am writing a macro to get annotations from a 'Class'
inline def getAnnotations(clazz: Class[?]): Seq[Any] = ${ getAnnotationsImpl('clazz) }
def getAnnotationsImpl(expr: Expr[Class[?]])(using Quot...
Gyrfalcon asked 8/3, 2022 at 4:41
1
I'm trying to override a method with use of Scala 3 macros and TASTY. I'd like to override any method of any type. Now I'm starting with this simple case.
I have a test base class:
class TestClass ...
Jabberwocky asked 27/7, 2021 at 19:48
1
Solved
Consider the following annotation:
// ok to have more meta
@field
@param
@compileTimeOnly("Only for code generation")
case class Annot(value: String) extends ConstantAnnotation
Now three...
Tendance asked 29/12, 2021 at 5:51
1
From the context of a Scala 3 Macro:
def aMacroImpl[T](using Type[T], Quotes): Expr[SpecialMap[_, _, _]] = {
import quotes.reflect._
val TRepr: TypeRepr = TypeRepr.of[T]
val TSym: Symbol = TRep...
Replacement asked 11/12, 2021 at 0:26
1
I would like to compile and execute Scala code given as a String at run-time using Scala3. Like for example in Scala 2 I would have used Reflection
import scala.reflect.runtime.universe as ru
impor...
Blowtube asked 1/2, 2022 at 17:58
1
Following the metaprogramming tutorial here, I am unable to get the fuseMap example to work. The macro I have is (in macros object)
def fuseMap[T: Type](x: Expr[List[T]])(using Quotes): Expr[List[...
Pic asked 8/6, 2022 at 18:29
0
This question is formulated in Scala 3/Dotty but should be generalised to any language NOT in MetaML family.
The Scala 3 macro tutorial:
https://docs.scala-lang.org/scala3/reference/metaprogramming...
Twice asked 14/4, 2022 at 18:57
2
Solved
Is there a clean way to access the default values of a case class fields when performing type class derivation in Scala 3 using Mirrors? For example:
case class Foo(s: String = "bar", i: ...
Law asked 17/7, 2021 at 13:42
1
Solved
I need to implement a testing function which checks compile-time error information for the "splain" plugin, part of this function needs to convert a codeblock into a string, e.g.:
def con...
Bowsprit asked 2/10, 2021 at 0:4
1
I defined the following trait in Scala 3:
trait A[T <: Tuple]
Using Scala 3 macros, I then create objects of this trait performing further checks on the actual types of the tuple T; in particul...
Breakable asked 26/8, 2021 at 15:55
1
Solved
I'm wondering if it is possible to write a macro in Scala 3 that take a set of strings and turn it into an enum type with with those strings as cases?
For example, I would like to write a class wit...
Woodring asked 17/9, 2021 at 18:1
1
Solved
I'm porting a macro from Scala 2 to Scala 3. As part of it's work, the Scala 2 macro creates an instance of a generic type using the default constructor. This is simple to do with a quasiquote in S...
Peirsen asked 28/5, 2021 at 12:26
0
I learned how to splice expr in quotes now. But I didn't find how to splice multiple exprs in a quote.
I have a selectable trait and a macro impl function:
trait StructuralTypeRoot extends Selectab...
Sparid asked 3/8, 2021 at 14:29
1
It is known in scala 2 that macros are strictly local and are only executed once, when the class is defined. This feature seems particularly weak when combining with abstract type, as the process t...
Ratcliff asked 25/4, 2021 at 21:1
1
Solved
Extracting names and types of elements of a case class at compile time in Scala 3 has been already explained well in this blog: https://blog.philipp-martini.de/blog/magic-mirror-scala3/
However, th...
Haemostasis asked 24/5, 2021 at 21:25
3
Solved
I'm struggling to get information of type in Scala3 macro implementation. I'll explain problem through code.
Here is application logic:
object BlockServiceImpl extends BlockService:
def authentica...
Outhouse asked 6/5, 2021 at 16:52
1 Next >
© 2022 - 2024 — McMap. All rights reserved.