Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

127 lines (54 sloc) 2.377 kb

Module ct_expand

Compile-time expansion utility. Authors: : Ulf Wiger (ulf@feuerlabs.com).

Description

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)'.

Data Types

form()


form() = any()

forms()


forms() = [form()]

options()


options() = [{atom(), any()}]

Function Index

extract_fun/3
lfun_rewrite/2
parse_transform/2

Function Details

extract_fun/3

extract_fun(Name, Arity, Forms) -> any()

lfun_rewrite/2

lfun_rewrite(Exprs, Forms) -> any()

parse_transform/2


parse_transform(Forms::forms(), Options::options()) -> forms()


Jump to Line
Something went wrong with that request. Please try again.