View Source ct_expand (parse_trans v3.4.2)

Compile-time expansion utility

This module serves as an example of parse_trans-based transforms, but might also be a useful utility in its own right. The transform searches for calls to the pseudo-function ct_expand:term(Expr), and then replaces the call site with the result of evaluating Expr at compile-time.

For example, the line

ct_expand:term(lists:sort([3,5,2,1,4]))

would be expanded at compile-time to [1,2,3,4,5].

ct_expand has now been extended to also evaluate calls to local functions. See examples/ct_expand_test.erl for some examples.

A debugging facility exists: passing the option {ct_expand_trace, Flags} as an option, or adding a compiler attribute -ct_expand_trace(Flags) will enable a form of call trace.

Flags can be [] (no trace) or [F], where F is c (call trace), r (return trace), or x (exception trace)'.

Summary

Types

-type abstract_expr() :: term().
-type form() :: any().
-type forms() :: [form()].
-type options() :: [{atom(), any()}].

Functions

Link to this function

extract_fun(Name, Arity, Forms)

View Source
Link to this function

lfun_rewrite(Exprs, Forms)

View Source
Link to this function

parse_transform(Forms, Options)

View Source
-spec parse_transform(forms(), options()) -> forms().