LINUX.ORG.RU

История изменений

Исправление Zenom, (текущая версия) :

покажи

import scala.reflect.macros.blackbox

/**
  * Created by zenom on 21.04.16.
  */
class MacroImpl(val c: blackbox.Context) {
  import c.universe._

  val function = reify((x: Int, y: Int) => x - y).tree

  def macroReplacer(function: c.Tree) = {
    val q"(..$params) => {$arg1.$op($arg2)}" = function
    q"(..$params) => {$arg1 + $arg2}"
  }

  def macroCombinator(fn: c.Tree, comb: c.Tree => c.Tree): c.Tree = comb(fn)

  def myMacro = macroCombinator(function, macroReplacer)
}

по-определению

Приведи определение полностью.

Исходная версия Zenom, :

покажи

import scala.reflect.macros.blackbox

/**
  * Created by zenom on 21.04.16.
  */
class MacroImpl(val c: blackbox.Context) {
  import c.universe._

  val function = reify((x: Int, y: Int) => x - y).tree

  def macroReplacer(function: c.Tree) = {
    val q"(..$params) => {$arg1.$op($arg2)}" = function
    q"(..$params) => {$arg1 + $arg2}"
  }

  def macroCombinator(fn: c.Tree, comb: c.Tree => c.Tree): c.Tree = comb(fn)

  def myMacro = macroCombinator(function, macroReplacer)
}

по-определению

Приведи определение полностью.