I'm trying to call a Shapeless macro from inside a quasiquote with Scala and I'm not getting what I would like to get.
My macro doesn't return any errors but it doesn't expand Witness(fieldName) into Witness.Lt[String]
val implicits =…
This question is similar in motivation to my previous question (although it's about a problem I ran into in a different context).
I can pattern match on a function literal pretty easily without quasiquotes:
import scala.reflect.macros.Context
import…
I'm new to scala macros and I spent a couple of days trying to write my very first one.
I have a problem with quasiquotes concatenation.
There is a list of case clauses, let's say the following:
val cases = cq"x => 1 " :: cq"_ => 0 " :: Nil
And I…
I was playing with Scala 2.11's new macro features. I wanted to see if I could do the following rewrite:
forRange(0 to 10) { i => println(i) }
// into
val iter = (0 to 10).iterator
while (iter.hasNext) {
val i = iter.next
println(i)
}
I think…
Quasiquotes are amazing—they make writing macros in Scala hugely less painful, and in my experience they almost always just work exactly as I'd expect. And best of all, they're now available as a plugin in Scala 2.10.
This question is about a small…
I'm trying to answer this question.
Instead of writing:
case class Person(name: String, age: Int) {
def this() = this("",1)
}
I thought I'd use macro annotations to expand it from:
@Annotation
case class Person(name: String, age: Int)
So I tried…
I want to transform Scala XML literals with a macro. (Not a string literal with XML but actual XML literals). As far as I understand, XML literals are not actually built into the language on the AST level but are desugared in the parser.…
I have a custom class, A, and I have defined some operations within the class as follows:
def +(that: A) = ...
def -(that: A) = ...
def *(that: A) = ...
def +(that: Double) = ...
def -(that: Double) = ...
def *(that: Double) = ...
In order to have…
I have an ostensibly simple macro problem that I’ve been banging my head against for a few hours, with no luck. Perhaps someone with more experience can help.
I have the following macro:
import scala.language.experimental.macros
import…
The following macro is pasted from http://docs.scala-lang.org/overviews/quasiquotes/usecases.html:
import reflect.macros.Context
import language.experimental.macros
val universe = reflect.runtime.universe; import universe._
import…
I am trying to convert an expression in Scala that is saved in database as String back to working code.
I have tried Reflect Toolbox, Groovy, etc. But I can't seem to achieve what I require.
Here's what I tried:
import…
OUTLINE
I have an API that looks something like this:
package com.example
object ExternalApi {
def create[T <: SpecialElement](elem: T): TypeConstructor[T] =
TypeConstructor(elem)
def create1[T <: SpecialElement](elem: T):…
Motivation:
(not tightly associated with this topic but states a use case. Skippable)
I'm using Scala.js to write React code. I now have a form which contains bunch of inputs, each needs a onChange callback in its props. See Controlled…
This is a simplified version of the problem I am facing but the underlying issue remains.
After calling a macro, I want to generate case classes dynamically. I am able to retrieve parameters from macro call etc. The issue I am having is trying to…
The Scala documentation for Quasiquotes mentions this when explaining Lifting:
One can also combine lifting and unquote splicing:
scala> val ints = List(1, 2, 3)
scala> val f123 = q"f(..$ints)"
f123: universe.Tree = f(1, 2, 3)
scala> val…