Macro Packages
Macro definitions must be placed in separate macro packages, declared using the macro package keyword. Packages qualified with macro package can only export macro definitions; other declarations are only visible within the package.
Macro packages need to import std.ast.* to use the Tokens type and tools like quote. Tokens represents Token sequences and is the core type for macro input and output. The quote expression is used to construct Token sequences.
The quote expression converts code fragments within parentheses into Tokens. Inside quote, you can use $(...) interpolation to insert the value of variables or expressions into the code fragment. For example, $(input) will insert the value of input.
Macro packages must first be compiled separately using cjc --compile-macro to generate a dynamic library file of macro definitions before they can be referenced by code that uses the macros.
The example on the right defines the simplest identity macro Identity, which receives input and returns it unchanged without any transformation. A macro is declared as public macro Name(input: Tokens): Tokens, where input is the Token sequence at the call site, and the return value replaces the macro call.
public func or public class.define.cj and the commented usage example as main.cj. Run cjc define.cj --compile-macro, then cjc main.cj --import-path . -o main && ./main. The online single-file runner does not support this multi-file build step.