Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8157375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:15:47+00:00 2026-06-06T17:15:47+00:00

I must integrate some macros in a project which is using a cake-pattern. That

  • 0

I must integrate some macros in a project which is using a cake-pattern. That pattern allowed us to avoid zillions of imports, among other advantages, so we would like to keep it. Now, we are facing a problem with some experimental macros we have been testing outside the trunk. First, let’s show a dummy system named Cake:

trait APiece {
  class A
}

trait BPiece { this: APiece => 
  def aMacro(a: A): Unit = () /* macro ??? */
}

trait CPiece { this: APiece with BPiece =>
  def aMacroInvoker = aMacro(new A)
}

class Cake { this: APiece with BPiece with CPiece => }

APiece defines a class, BPiece is supposed to be a macro which uses the APiece defined class, and finally, CPiece invokes the macro. I said that BPiece was supposed to be a macro since I was unable to code an implementation for it. I have tried several ways but I always crash with the following error:

"macro implementation must be in statically accessible object"

Reading the macros code one can guess that it is neccesary to enclose the macro in a static module. Is there any way to deploy a macro which uses the system structures?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:15:49+00:00Added an answer on June 6, 2026 at 5:15 pm

    Luckily there’s an easy solution to your problem.

    But first, let me give some retrospective. In the very first prototype, macros were defined like that: def macro aMacro(a: A): Unit = .... One of the major breakthroughs we’ve had when preparing a SIP is separating macro definitions (public faces of macros) and macro implementations (tree transformers that host macro logic). It took me a while realize how cool this is, but now I’m glowing with joy every time when I write a macro declaration.

    So, back to your question. Sure, macro implementations have to be statically accessible (otherwise, compiler won’t be able to load and invoke them during the compilation). However macro definitions don’t have this restriction, so you can write the definition like that:

    trait BPiece { this: APiece => 
      def aMacro(a: A): Unit = macro Macros.aMacro
    }
    

    Macro implementation that is referred to from the definition can be put into whatever object you wish, even into a different compilation unit.

    The only missing piece of puzzle is how we’re going to refer to A from the implementation, because A is defined inside a cake. The simplest way would be to make aMacro generic and rely on type inference:

    (update: to make this example work in 2.10.0-M7, you need to replace c.TypeTag with c.AbsTypeTag; to make this example work in 2.10.0-RC1, c.AbsTypeTag needs to be replaced with c.WeakTypeTag)

    trait BPiece { this: APiece =>
      def aMacro[A](a: A): Unit = macro Macros.aMacro[A]
    }
    
    object Macros {
      def aMacro[A: c.TypeTag](c: Context)(a: c.Expr[A]): c.Expr[Unit] = c.literalUnit
    }
    

    This won’t let you use reify, though, because for a macro implementation A is just a type parameter without any members. There are also going to be problems if you’ll want to return something cake-specific from the macro, but let’s deal with them when they arise. Please, submit follow-up questions if you need to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create some tunnel software which should integrate into Windows by
So we've got ourselves a lovely vintage PHP WS we must integrate via JAX-RPC
I'm using Django to create a site that provides a separate web UI for
I'm trying to integrate ELMAH in a webforms application. For reasons that I am
I must be missing something pretty basic. I'm working on a legacy project, and
I want to integrate Wordpress blog in my Cake PHP Site. When I logged
Trying to choose a PHP open source CMS into which I will integrate an
I find myself in a situation that someone else must have got stuck in
I got some problems when I try to integrate the plugin Phonegap-plugin-facebook-connect in to
I am tryin to integrate Facebook in my Android app. In some tutorials, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.