- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Quasiquotes 的 Scala 文档在解释 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 intss = List(List(1, 2, 3), List(4, 5), List(6))
scala> val f123456 = q"f(...$intss)"
f123456: universe.Tree = f(1, 2, 3)(4, 5)(6)
最佳答案
在这两个示例中,两者同时发生。
取消引用是替换 Tree
的过程某处进入另一个 Tree
的结构(如插值)。在本例中,ints
不完全是 Tree
,但存在一个 Liftable[List[T]]
这允许我们取消引用 List[T]
成Tree
,就好像它是一个 Tree
(即 Liftable
告诉编译器如何将这里的文字 List[Int]
转换为 Tree
以便它可以被替换)。
引用文档:
Unquote splicing is a way to unquote a variable number of elements.
List
中的元素。我们想取消报价。如果我们这样做了
q"f($ints)"
,那么我们将简单地取消引用
ints
作为
f
的单个参数.但也许我们想对
f
应用重复的参数反而。为此,我们使用无引号拼接。
q"f(..$ints) // Using `..` means we get f(1, 2, 3) instead of f(List(1, 2, 3))
Dots near unquotee annotate degree of flattening and are also called splicing rank.
..$
expects argument to be anIterable[Tree]
and...$
expectsIterable[Iterable[Tree]]
.
List[T]
进树
f(x)
好像它是一个
Iterable[Tree]
,并且取消引用拼接允许我们取消引用可变数量的元素
List[T]
包含为
f
的多个参数.
val listTree = q"scala.collection.immutable.List(1, 2, 3)"
val treeList = List(q"1", q"2", q"3")
val literalList = List(1, 2, 3)
scala> q"f($listTree)" // plain unquoting from another Tree
res6: reflect.runtime.universe.Tree = f(scala.collection.immutable.List(1, 2, 3))
scala> q"f($literalList)" // unquoting from lifting
res7: reflect.runtime.universe.Tree = f(scala.collection.immutable.List(1, 2, 3))
scala> q"f(..$treeList)" // plain unquote splicing
res8: reflect.runtime.universe.Tree = f(1, 2, 3)
scala> q"f(..$literalList)" // unquote splicing and lifting
res9: reflect.runtime.universe.Tree = f(1, 2, 3)
关于Scala Quasiquote 提升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30155938/
Quasiquotes 的 Scala 文档在解释 Lifting 时提到了这一点: One can also combine lifting and unquote splicing: scala
我刚刚开始学习 Scala 编译时反射,并且通过 Scala 官方指南向我介绍了 quasiquotes。 我仍在努力解决的一个概念是,如果我想为已定义的对象生成 AST,我应该如何使用 quasiq
我想用 Haskell 写一个引用。需要将 name 参数传递给 gen 函数以生成声明。 quote :: String -> QuasiQuoter quote name = QuasiQuot
不幸的是,最直观的方式, val world = "Earth" val tree = q"""println("Hello $world")""" 结果 Error:(16, 36) Don't k
我正在尝试将 OverloadedLabels 与 here 包中的 QuasiQuotes 一起使用。使用普通镜头可以,但 #foo 在编译期间因解析错误而失败。 field @"foo" 也是如此
我正在尝试在 R 中编写一个函数,根据分组变量汇总数据框。分组变量作为列表给出并传递给 group_by_at ,我想对它们进行参数化。 我现在正在做的是: library(tidyverse) d
documentation对于模板 Haskell 说 QuasiQuoter 被定义为 data QuasiQuoter = QuasiQuoter { quoteExp :: String ->
我正在使用 macroparadise 2.0.0-M3 在 Scala 2.10.3 中试验宏注释。我试图了解如何使用 quasiquotes 为带注释的类生成伴随对象。到目前为止,我发现的是如何在
通读Why It’s Nice to be Quoted ,在第 3 节中有一个在准引号中拼接变量标识符的示例。 subst [:lam | $exp:e1 $exp:e2 |] x y =
我正在尝试实现一个隐式实现器,如下所述:http://docs.scala-lang.org/overviews/macros/implicits.html 我决定创建一个宏,该宏使用准引号将案例类与
我正在尝试使用 Scala 从 quasiquote 内部调用 Shapeless 宏,但没有得到我想要的结果得到。 我的宏不返回任何错误,但它不会将 Witness(fieldName) 扩展为 W
我正在尝试使用 scala-pickling在my project之一秒。我试过 mimic macroid 的构建文件这似乎也使用酸洗,但我在 sbt test 上不断收到此错误: [error]
这是我面临的问题的简化版本,但潜在的问题仍然存在。 调用宏后,我想动态生成案例类。我能够从宏调用等中检索参数。我遇到的问题是尝试在 quasiquotes 中使用字符串变量。我基本上想要以下内容: d
我怎样才能像这样插值: {-# LANGUAGE QuasiQuotes #-} import Text.RawString.QQ myText :: Text -> Text myText myVa
我很好奇为什么 purrr::map_*函数家族,尽管是 tidyverse 的一部分, 不支持通过拼接取消引用其 dots 的准引用在评估映射函数之前? library(tidyverse) lib
这个问题的动机与我的 previous question 相似(尽管这是关于我在 different context 中遇到的问题)。 我可以很容易地对函数文字进行模式匹配,而无需 quasiquot
我正在尝试搜索数据库,然后使用源自原始搜索的名称标记输出,"derived_name"在下面的可重现示例中。我正在使用 dplyr管道 %>% ,并且我在准报价和/或非标准评估方面遇到了麻烦。具体来说
背景 : 我正在研究哈姆雷特是如何工作的,有 WAI,但没有 Yesod。我没有掌握模板 Haskell,但在我深入研究它之前,我想知道是否有一个已知/快速的解决方案来完成这项任务。 规范 : 我想知
haskellwiki 中所述的准报价主要显示为在 Haskell 中嵌入其他语言的有用工具,而不会弄乱字符串引用。 问题是:对于 Haskell 本身,将现有的 Haskell 代码放入一个 qua
我正在尝试编写一个自定义函数,我使用 rlang的准报价。此函数也在内部使用 dplyr的 join职能。我在下面提供了一个最小的工作示例来说明我的问题。 # needed libraries lib
我是一名优秀的程序员,十分优秀!