Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If nothing changes until release it should look like this in Scala:

  # without macro
  def addTwo(x: Int) = x + 2

  # with macro
  def addTwo(x: Int) = macro addTwoImpl
  def addTwoImpl(c: Context)(x: c.Expr[Int]): c.Expr[Int] = c.reify(x + 2)
It used to look like this in earlier proposal:

  macro def addTwo(c: Context)(x: c.Expr[Int]): c.Expr[Int] = c.reify(x + 2)
Here c.reify is similar to quoting in lisp version. It really should have been something like:

  macro def addTwo(x: Expr[Int]): Expr[Int] = reify(x + 2)
It almost feels like they are making syntax more cumbersome on purpose to make inexperienced people not to use it. On the other hand they may require explicit Context to have purer API from their stand point. From end-user perspective it would be much simpler to have it in some singleton class as there most likely will never be two different contexts in a real-life macro.


Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: