Documentation for gololang.macros

This module defines the set of predefined macros. It is &used by default.

Submodules

Macros

deprecated(args...)

Macro to mark an element as deprecated.

Can be used as a toplevel macro decorator. For instance, to mark a function as deprecated:

@deprecated
function foo = |a, b| -> a + b

Moreover, some additional informations can be provided. They are used to modify the element documentation.

@deprecated(since="3.4", comment="Use `gololang.Functions::add` instead")
function foo = |a, b| -> a + b

See also gololang.meta.Annotations::makeDeprecated

dontExpandRegularCalls(visitor)

Don't try to expand regular calls as macros.

This special macro configure the expansion process to not be tried on regular function invocations. Only explicit macro calls (prefixed with &) are expanded.

dontRecurse(visitor)

Don't expand the result of a macro.

This special macro configure the expansion process to not expand the macros contained in the result of a macro expansion. This can be useful for debugging, to diagnose intermediary steps.

meta(args...)

Adds metadata to an element.

The metadata can be used by another macro, for instance to conditionally deal with the marked element.

The metadata value must be a value convertible by gololang.macros.Utils::getLiteralValue

This macro is called with named parameters for metadata followed with the element to annotate, as in:

@meta(foo="bar", answer=42)
function example = -> null

It is similar to withMetadata, but with a more convenient syntax, and allows to add several metadata at once.

See also withMetadata

recursionLimit(visitor, limit)

Define the recursion limit for macro expansion in the current module.

This setting only takes effect for macros following it.

use(visitor, mod, args...)

Adds a module in the macro resolution scope.

Modules added with this special macro are used for macro resolution, but are not imported. They does not appear in the compiled code, and are not used for regular function invocation resolutions.

Moreover, if the used module has a macro named init, a call to this macro, using the additional parameters of use, is injected into the module.

For instance:

module Test

&use("my.macros", "answer", 42)

configures the visitor to lookup macros in the my.macros module, and expands to

module Test

&my.macros.init("answer", 42)

The init macro may be contextual, to further modify the calling module.

useOldstyleDestruct(self)

Use old-style destructuring for the current module.

This macro customize the behavior of the destructuring feature by forcing the use of the destruct method instead of _$$_destruct.

This is a toplevel macro.

withMetadata(key, value, element)

Adds metadata to an element.

The metadata can be used by another macro, for instance to conditionally deal with the marked element.

The metadata value must be a value convertible by gololang.macros.Utils::getLiteralValue

This macro is similar to meta, but allows to use a key with a name not allowed by the named parameter syntax (for instance "foo.bar Bz".

See also meta