cerl_trees(3)

๐Ÿ“ฆ
version 29.0.6 ยท 3 versions
, in ubuntu stonking

โœจ cerl_trees ๐Ÿ’–

okay bestie, welcome to cerl_trees(3) โ€” it's an Erlang module, and it's literally the module of basic functions on Core Erlang abstract syntax trees. trees!! ๐ŸŒณโœจ we love a tree moment.


๐ŸŒธ DESCRIPTION ๐ŸŒธ

NOTE: the public interface of the Erlang compiler can be found in module compile. This module is an internal part of the compiler. Its API is not guaranteed to remain compatible between releases. ๐Ÿซ  so like, use it with your whole chest if you must, but know that it can change on you without warning. it's giving "situationship with the API".

Syntax trees are defined in the module cerl. ๐Ÿฆ‹


๐ŸŽ€ DATA TYPES ๐ŸŽ€

the one and only:

cerl() :: cerl:cerl().

that's it. that's the type. iconic. ๐Ÿ’…


๐Ÿ‘‘ FUNCTIONS ๐Ÿ‘‘

โญ depth(Tree :: cerl()) -> non_neg_integer().

depth(Tree :: cerl()) -> non_neg_integer().

Returns the length of the longest path in the tree.

and ngl the depth counting starts at zero, so: a leaf node has depth zero, the tree representing {foo, bar} has depth one, and so on. ๐Ÿ“


โญ fold(Function, Unit, Term)

fold(Function :: fun((cerl(), term()) -> term()),
            Unit :: term(),
            Term :: cerl()) ->
               term().

Does a fold operation over the nodes of the tree.

The result is the value of Function(X1, Function(X2, ... Function(Xn, Unit) ... )), where X1, ..., Xn are the nodes of Tree in a post-order traversal. ๐ŸŒˆ

See also: mapfold/3.


โญ free_variables(Tree :: cerl()) -> [cerl:var_name()].

free_variables(Tree :: cerl()) -> [cerl:var_name()].

Like variables/1, but only includes variables that are free in the tree. so it's variables/1's more selective cousin ๐Ÿ’…

See also: next_free_variable_name/1, variables/1.


โญ get_label(Tree :: cerl()) -> top | integer().

get_label(Tree :: cerl()) -> top | integer().

Retrieves the label for Tree. ๐Ÿท๏ธ

An exception is thrown if Tree does not have a label, or if Tree does not represent a well-formed Core Erlang syntax tree. so don't come for it with garbage fr fr ๐Ÿ˜ญ

โญ label(cerl()) -> {cerl(), integer()}.

label(cerl()) -> {cerl(), integer()}.

Equivalent to label(Tree, 0). short king behavior ๐Ÿซถ


โญ label(Tree :: cerl(), N :: integer()) -> {cerl(), integer()}.

label(Tree :: cerl(), N :: integer()) -> {cerl(), integer()}.

Labels each expression in the tree! ๐Ÿท๏ธโœจ

A term {label, L} is prefixed to the annotation list of each expression node, where L is a unique number for every node โ€” except for variables (and function name variables), which get the same label if they represent the same variable. Constant literal nodes are not labeled. okay so they said "consistency" and we said slay.

The returned value is a tuple {NewTree, Max}, where NewTree is the labeled tree and Max is 1 plus the largest label value used. All previous annotation terms of the form {label, X} are deleted. bye ๐Ÿ‘‹

The values of L used in the tree is a dense range from N to Max - 1, where N =< Max =< N + size(Tree). Note that it is possible that no labels are used at all, i.e., N = Max. ๐Ÿ’€

Note: all instances of free variables will be given distinct labels.

See also: label/1, size/1.


โญ map(Function :: fun((cerl()) -> cerl()), Tree :: cerl()) -> cerl().

map(Function :: fun((cerl()) -> cerl()), Tree :: cerl()) -> cerl().

Maps a function onto the nodes of a tree. ๐Ÿ—บ๏ธ

This replaces each node in the tree by the result of applying the given function on the original node, bottom-up. yes bestie, bottom-up, we go from the leaves to the root ๐ŸŒฑโžก๏ธ๐ŸŒณ

See also: mapfold/3.


โญ mapfold(Function, Initial, Tree)

mapfold(Function :: fun((cerl(), term()) -> {cerl(), term()}),
               Initial :: term(),
               Tree :: cerl()) ->
                  {cerl(), term()}.

Does a combined map/fold operation on the nodes of the tree. it's both. it's multifaceted. it contains multitudes. ๐Ÿ’…

This is similar to map/2, but also propagates a value from each application of Function to the next, starting with the given value Initial, while doing a post-order traversal of the tree, much like fold/3.

This is equivalent to mapfold/4 with an identity function as the pre-operation.

See also: fold/3, map/2, mapfold/4.


โญ mapfold(Pre, Post, Initial, Tree)

mapfold(Pre :: fun((cerl(), term()) -> {cerl(), term()} | skip),
               Post :: fun((cerl(), term()) -> {cerl(), term()}),
               Initial :: term(),
               Tree :: cerl()) ->
                  {cerl(), term()}.

Does a combined map/fold operation on the nodes of the tree. (the four-argument glow-up โœจ)

It begins by calling Pre on the tree, using the Initial value. Pre must either return a tree with an updated accumulator or the atom skip. ๐Ÿ‘€

If a tree is returned, this function deconstructs the top node of the returned tree and recurses on the children, using the returned value as the new initial and carrying the returned values from one call to the next. Finally it reassembles the top node from the children, calls Post on it and returns the result.

If skip is returned, it returns the tree and accumulator as is. no touchy. ๐Ÿ™ˆ


โญ next_free_variable_name(Tree :: cerl()) -> integer().

next_free_variable_name(Tree :: cerl()) -> integer().

Returns a integer variable name higher than any other integer variable name in the syntax tree. ๐Ÿ“ˆ

An exception is thrown if Tree does not represent a well-formed Core Erlang syntax tree.

See also: free_variables/1, variables/1.


โญ size(Tree :: cerl()) -> non_neg_integer().

size(Tree :: cerl()) -> non_neg_integer().

Returns the number of nodes in Tree. that's it bestie, just counting ๐Ÿงฎ


โญ variables(Tree :: cerl()) -> [cerl:var_name()].

variables(Tree :: cerl()) -> [cerl:var_name()].

Returns an ordered-set list of the names of all variables in the syntax tree (including function-name variables.) ๐Ÿซถ

An exception is thrown if Tree does not represent a well-formed Core Erlang syntax tree.

See also: free_variables/1, next_free_variable_name/1.


and that's the whole page, bestie!! ๐ŸŽ€๐Ÿ’– go forth and traverse your trees, you absolute icon ๐Ÿ‘‘

Ericsson AB made this one, and it's from compiler 10.0.4, cerl_trees(3). mwah ๐Ÿ’‹ periodt. ๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from