Erlang -- ms_transform

STDLIB

Reference Manual

Version 3.13

- User's Guide
- Reference Manual
- Release Notes
- PDF
- Top

- Expand All
- Contract All

### Table of Contents

- STDLIB (App)
- array
  - Top of manual page
  - default/1
  - fix/1
  - foldl/3
  - foldr/3
  - from_list/1
  - from_list/2
  - from_orddict/1
  - from_orddict/2
  - get/2
  - is_array/1
  - is_fix/1
  - map/2
  - new/0
  - new/1
  - new/2
  - relax/1
  - reset/2
  - resize/1
  - resize/2
  - set/3
  - size/1
  - sparse_foldl/3
  - sparse_foldr/3
  - sparse_map/2
  - sparse_size/1
  - sparse_to_list/1
  - sparse_to_orddict/1
  - to_list/1
  - to_orddict/1
- assert.hrl
- base64
  - Top of manual page
  - decode/1
  - decode_to_string/1
  - encode/1
  - encode_to_string/1
  - mime_decode/1
  - mime_decode_to_string/1
- beam_lib
  - Top of manual page
  - all_chunks/1
  - build_module/1
  - chunks/2
  - chunks/3
  - clear_crypto_key_fun/0
  - cmp/2
  - cmp_dirs/2
  - crypto_key_fun/1
  - diff_dirs/2
  - format_error/1
  - info/1
  - md5/1
  - strip/1
  - strip/2
  - strip_files/1
  - strip_files/2
  - strip_release/1
  - strip_release/2
  - version/1
- binary
  - Top of manual page
  - at/2
  - bin_to_list/1
  - bin_to_list/2
  - bin_to_list/3
  - compile_pattern/1
  - copy/1
  - copy/2
  - decode_unsigned/1
  - decode_unsigned/2
  - encode_unsigned/1
  - encode_unsigned/2
  - first/1
  - last/1
  - list_to_bin/1
  - longest_common_prefix/1
  - longest_common_suffix/1
  - match/2
  - match/3
  - matches/2
  - matches/3
  - part/2
  - part/3
  - referenced_byte_size/1
  - replace/3
  - replace/4
  - split/2
  - split/3
- c
  - Top of manual page
  - bt/1
  - c/1
  - c/2
  - c/3
  - cd/1
  - erlangrc/1
  - flush/0
  - h/1
  - h/2
  - h/3
  - help/0
  - ht/1
  - ht/2
  - ht/3
  - i/0
  - i/3
  - l/1
  - lc/1
  - lm/0
  - ls/0
  - ls/1
  - m/0
  - m/1
  - memory/0
  - memory/1
  - mm/0
  - nc/1
  - nc/2
  - ni/0
  - nl/1
  - nregs/0
  - pid/3
  - pwd/0
  - q/0
  - regs/0
  - uptime/0
  - xm/1
  - y/1
  - y/2
- calendar
  - Top of manual page
  - date_to_gregorian_days/1
  - date_to_gregorian_days/3
  - datetime_to_gregorian_seconds/1
  - day_of_the_week/1
  - day_of_the_week/3
  - gregorian_days_to_date/1
  - gregorian_seconds_to_datetime/1
  - is_leap_year/1
  - iso_week_number/0
  - iso_week_number/1
  - last_day_of_the_month/2
  - local_time/0
  - local_time_to_universal_time/1
  - local_time_to_universal_time_dst/1
  - now_to_datetime/1
  - now_to_local_time/1
  - now_to_universal_time/1
  - rfc3339_to_system_time/1
  - rfc3339_to_system_time/2
  - seconds_to_daystime/1
  - seconds_to_time/1
  - system_time_to_local_time/2
  - system_time_to_rfc3339/1
  - system_time_to_rfc3339/2
  - system_time_to_universal_time/2
  - time_difference/2
  - time_to_seconds/1
  - universal_time/0
  - universal_time_to_local_time/1
  - valid_date/1
  - valid_date/3
- dets
  - Top of manual page
  - all/0
  - bchunk/2
  - close/1
  - delete/2
  - delete_all_objects/1
  - delete_object/2
  - first/1
  - foldl/3
  - foldr/3
  - from_ets/2
  - info/1
  - info/2
  - init_table/2
  - init_table/3
  - insert/2
  - insert_new/2
  - is_compatible_bchunk_format/2
  - is_dets_file/1
  - lookup/2
  - match/1
  - match/2
  - match/3
  - match_delete/2
  - match_object/1
  - match_object/2
  - match_object/3
  - member/2
  - next/2
  - open_file/1
  - open_file/2
  - pid2name/1
  - repair_continuation/2
  - safe_fixtable/2
  - select/1
  - select/2
  - select/3
  - select_delete/2
  - slot/2
  - sync/1
  - table/1
  - table/2
  - to_ets/2
  - traverse/2
  - update_counter/3
- dict
  - Top of manual page
  - append/3
  - append_list/3
  - erase/2
  - fetch/2
  - fetch_keys/1
  - filter/2
  - find/2
  - fold/3
  - from_list/1
  - is_empty/1
  - is_key/2
  - map/2
  - merge/3
  - new/0
  - size/1
  - store/3
  - take/2
  - to_list/1
  - update/3
  - update/4
  - update_counter/3
- digraph
  - Top of manual page
  - add_edge/3
  - add_edge/4
  - add_edge/5
  - add_vertex/1
  - add_vertex/2
  - add_vertex/3
  - del_edge/2
  - del_edges/2
  - del_path/3
  - del_vertex/2
  - del_vertices/2
  - delete/1
  - edge/2
  - edges/1
  - edges/2
  - get_cycle/2
  - get_path/3
  - get_short_cycle/2
  - get_short_path/3
  - in_degree/2
  - in_edges/2
  - in_neighbours/2
  - info/1
  - new/0
  - new/1
  - no_edges/1
  - no_vertices/1
  - out_degree/2
  - out_edges/2
  - out_neighbours/2
  - vertex/2
  - vertices/1
- digraph_utils
  - Top of manual page
  - arborescence_root/1
  - components/1
  - condensation/1
  - cyclic_strong_components/1
  - is_acyclic/1
  - is_arborescence/1
  - is_tree/1
  - loop_vertices/1
  - postorder/1
  - preorder/1
  - reachable/2
  - reachable_neighbours/2
  - reaching/2
  - reaching_neighbours/2
  - strong_components/1
  - subgraph/2
  - subgraph/3
  - topsort/1
- epp
  - Top of manual page
  - close/1
  - default_encoding/0
  - encoding_to_string/1
  - format_error/1
  - open/1
  - open/2
  - open/3
  - parse_erl_form/1
  - parse_file/2
  - parse_file/3
  - read_encoding/1
  - read_encoding/2
  - read_encoding_from_binary/1
  - read_encoding_from_binary/2
  - set_encoding/1
  - set_encoding/2
- erl_anno
  - Top of manual page
  - column/1
  - end_location/1
  - file/1
  - from_term/1
  - generated/1
  - is_anno/1
  - line/1
  - location/1
  - new/1
  - set_file/2
  - set_generated/2
  - set_line/2
  - set_location/2
  - set_record/2
  - set_text/2
  - text/1
  - to_term/1
- erl_eval
  - Top of manual page
  - add_binding/3
  - binding/2
  - bindings/1
  - del_binding/2
  - expr/2
  - expr/3
  - expr/4
  - expr/5
  - expr_list/2
  - expr_list/3
  - expr_list/4
  - exprs/2
  - exprs/3
  - exprs/4
  - new_bindings/0
- erl_expand_records
  - Top of manual page
  - module/2
- erl_id_trans
  - Top of manual page
  - parse_transform/2
- erl_internal
  - Top of manual page
  - add_predefined_functions/1
  - arith_op/2
  - bif/2
  - bool_op/2
  - comp_op/2
  - guard_bif/2
  - list_op/2
  - op_type/2
  - send_op/2
  - type_test/2
- erl_lint
  - Top of manual page
  - format_error/1
  - is_guard_test/1
  - module/1
  - module/2
  - module/3
- erl_parse
  - Top of manual page
  - abstract/1
  - abstract/2
  - anno_from_term/1
  - anno_to_term/1
  - fold_anno/3
  - format_error/1
  - map_anno/2
  - mapfold_anno/3
  - new_anno/1
  - normalise/1
  - parse_exprs/1
  - parse_form/1
  - parse_term/1
  - tokens/1
  - tokens/2
- erl_pp
  - Top of manual page
  - attribute/1
  - attribute/2
  - expr/1
  - expr/2
  - expr/3
  - expr/4
  - exprs/1
  - exprs/2
  - exprs/3
  - form/1
  - form/2
  - function/1
  - function/2
  - guard/1
  - guard/2
- erl_scan
  - Top of manual page
  - category/1
  - column/1
  - end_location/1
  - format_error/1
  - line/1
  - location/1
  - reserved_word/1
  - string/1
  - string/2
  - string/3
  - symbol/1
  - text/1
  - tokens/3
  - tokens/4
- erl_tar
  - Top of manual page
  - add/3
  - add/4
  - close/1
  - create/2
  - create/3
  - extract/1
  - extract/2
  - format_error/1
  - init/3
  - open/2
  - t/1
  - table/1
  - table/2
  - tt/1
- ets
  - Top of manual page
  - all/0
  - delete/1
  - delete/2
  - delete_all_objects/1
  - delete_object/2
  - file2tab/1
  - file2tab/2
  - first/1
  - foldl/3
  - foldr/3
  - from_dets/2
  - fun2ms/1
  - give_away/3
  - i/0
  - i/1
  - info/1
  - info/2
  - init_table/2
  - insert/2
  - insert_new/2
  - is_compiled_ms/1
  - last/1
  - lookup/2
  - lookup_element/3
  - match/1
  - match/2
  - match/3
  - match_delete/2
  - match_object/1
  - match_object/2
  - match_object/3
  - match_spec_compile/1
  - match_spec_run/2
  - member/2
  - new/2
  - next/2
  - prev/2
  - rename/2
  - repair_continuation/2
  - safe_fixtable/2
  - select/1
  - select/2
  - select/3
  - select_count/2
  - select_delete/2
  - select_replace/2
  - select_reverse/1
  - select_reverse/2
  - select_reverse/3
  - setopts/2
  - slot/2
  - tab2file/2
  - tab2file/3
  - tab2list/1
  - tabfile_info/1
  - table/1
  - table/2
  - take/2
  - test_ms/2
  - to_dets/2
  - update_counter/3
  - update_counter/4
  - update_element/3
  - whereis/1
- file_sorter
  - Top of manual page
  - check/1
  - check/2
  - keycheck/2
  - keycheck/3
  - keymerge/3
  - keymerge/4
  - keysort/2
  - keysort/3
  - keysort/4
  - merge/2
  - merge/3
  - sort/1
  - sort/2
  - sort/3
- filelib
  - Top of manual page
  - ensure_dir/1
  - file_size/1
  - find_file/2
  - find_file/3
  - find_source/1
  - find_source/2
  - find_source/3
  - fold_files/5
  - is_dir/1
  - is_file/1
  - is_regular/1
  - last_modified/1
  - safe_relative_path/2
  - wildcard/1
  - wildcard/2
- filename
  - Top of manual page
  - absname/1
  - absname/2
  - absname_join/2
  - basedir/2
  - basedir/3
  - basename/1
  - basename/2
  - dirname/1
  - extension/1
  - find_src/1
  - find_src/2
  - flatten/1
  - join/1
  - join/2
  - nativename/1
  - pathtype/1
  - rootname/1
  - rootname/2
  - safe_relative_path/1
  - split/1
- gb_sets
  - Top of manual page
  - add/2
  - add_element/2
  - balance/1
  - del_element/2
  - delete/2
  - delete_any/2
  - difference/2
  - empty/0
  - filter/2
  - fold/3
  - from_list/1
  - from_ordset/1
  - insert/2
  - intersection/1
  - intersection/2
  - is_disjoint/2
  - is_element/2
  - is_empty/1
  - is_member/2
  - is_set/1
  - is_subset/2
  - iterator/1
  - iterator_from/2
  - largest/1
  - new/0
  - next/1
  - singleton/1
  - size/1
  - smallest/1
  - subtract/2
  - take_largest/1
  - take_smallest/1
  - to_list/1
  - union/1
  - union/2
- gb_trees
  - Top of manual page
  - balance/1
  - delete/2
  - delete_any/2
  - empty/0
  - enter/3
  - from_orddict/1
  - get/2
  - insert/3
  - is_defined/2
  - is_empty/1
  - iterator/1
  - iterator_from/2
  - keys/1
  - largest/1
  - lookup/2
  - map/2
  - next/1
  - size/1
  - smallest/1
  - take/2
  - take_any/2
  - take_largest/1
  - take_smallest/1
  - to_list/1
  - update/3
  - values/1
- gen_event
  - Top of manual page
  - add_handler/3
  - add_sup_handler/3
  - call/3
  - call/4
  - check_response/2
  - delete_handler/3
  - notify/2
  - send_request/3
  - start/0
  - start/1
  - start/2
  - start_link/0
  - start_link/1
  - start_link/2
  - start_monitor/0
  - start_monitor/1
  - start_monitor/2
  - stop/1
  - stop/3
  - swap_handler/3
  - swap_sup_handler/3
  - sync_notify/2
  - wait_response/2
  - which_handlers/1
  - Module:code_change/3
  - Module:format_status/2
  - Module:handle_call/2
  - Module:handle_event/2
  - Module:handle_info/2
  - Module:init/1
  - Module:terminate/2
- gen_fsm
- gen_server
  - Top of manual page
  - abcast/2
  - abcast/3
  - call/2
  - call/3
  - cast/2
  - check_response/2
  - enter_loop/3
  - enter_loop/4
  - enter_loop/4
  - enter_loop/5
  - multi_call/2
  - multi_call/3
  - multi_call/4
  - reply/2
  - send_request/2
  - start/3
  - start/4
  - start_link/3
  - start_link/4
  - start_monitor/3
  - start_monitor/4
  - stop/1
  - stop/3
  - wait_response/2
  - Module:code_change/3
  - Module:format_status/2
  - Module:handle_call/3
  - Module:handle_cast/2
  - Module:handle_continue/2
  - Module:handle_info/2
  - Module:init/1
  - Module:terminate/2
- gen_statem
  - Top of manual page
  - call/2
  - call/3
  - cast/2
  - check_response/2
  - enter_loop/4
  - enter_loop/5
  - enter_loop/6
  - reply/1
  - reply/2
  - send_request/2
  - start/3
  - start/4
  - start_link/3
  - start_link/4
  - start_monitor/3
  - start_monitor/4
  - stop/1
  - stop/3
  - wait_response/1
  - wait_response/2
  - Module:StateName/3
  - Module:StateName/3
  - Module:callback_mode/0
  - Module:code_change/4
  - Module:format_status/2
  - Module:handle_event/4
  - Module:handle_event/4
  - Module:init/1
  - Module:terminate/3
- io
  - Top of manual page
  - columns/0
  - columns/1
  - format/1
  - format/2
  - format/3
  - fread/2
  - fread/3
  - fwrite/1
  - fwrite/2
  - fwrite/3
  - get_chars/2
  - get_chars/3
  - get_line/1
  - get_line/2
  - getopts/0
  - getopts/1
  - nl/0
  - nl/1
  - parse_erl_exprs/1
  - parse_erl_exprs/2
  - parse_erl_exprs/3
  - parse_erl_exprs/4
  - parse_erl_form/1
  - parse_erl_form/2
  - parse_erl_form/3
  - parse_erl_form/4
  - printable_range/0
  - put_chars/1
  - put_chars/2
  - read/1
  - read/2
  - read/3
  - read/4
  - rows/0
  - rows/1
  - scan_erl_exprs/1
  - scan_erl_exprs/2
  - scan_erl_exprs/3
  - scan_erl_exprs/4
  - scan_erl_form/1
  - scan_erl_form/2
  - scan_erl_form/3
  - scan_erl_form/4
  - setopts/1
  - setopts/2
  - write/1
  - write/2
- io_lib
  - Top of manual page
  - build_text/1
  - char_list/1
  - deep_char_list/1
  - deep_latin1_char_list/1
  - format/2
  - format/3
  - fread/2
  - fread/3
  - fwrite/2
  - fwrite/3
  - indentation/2
  - latin1_char_list/1
  - nl/0
  - print/1
  - print/4
  - printable_latin1_list/1
  - printable_list/1
  - printable_unicode_list/1
  - scan_format/2
  - unscan_format/1
  - write/1
  - write/2
  - write_atom/1
  - write_atom_as_latin1/1
  - write_char/1
  - write_char_as_latin1/1
  - write_latin1_char/1
  - write_latin1_string/1
  - write_string/1
  - write_string_as_latin1/1
- lists
  - Top of manual page
  - all/2
  - any/2
  - append/1
  - append/2
  - concat/1
  - delete/2
  - droplast/1
  - dropwhile/2
  - duplicate/2
  - filter/2
  - filtermap/2
  - flatlength/1
  - flatmap/2
  - flatten/1
  - flatten/2
  - foldl/3
  - foldr/3
  - foreach/2
  - join/2
  - keydelete/3
  - keyfind/3
  - keymap/3
  - keymember/3
  - keymerge/3
  - keyreplace/4
  - keysearch/3
  - keysort/2
  - keystore/4
  - keytake/3
  - last/1
  - map/2
  - mapfoldl/3
  - mapfoldr/3
  - max/1
  - member/2
  - merge/1
  - merge/2
  - merge/3
  - merge3/3
  - min/1
  - nth/2
  - nthtail/2
  - partition/2
  - prefix/2
  - reverse/1
  - reverse/2
  - search/2
  - seq/2
  - seq/3
  - sort/1
  - sort/2
  - split/2
  - splitwith/2
  - sublist/2
  - sublist/3
  - subtract/2
  - suffix/2
  - sum/1
  - takewhile/2
  - ukeymerge/3
  - ukeysort/2
  - umerge/1
  - umerge/2
  - umerge/3
  - umerge3/3
  - unzip/1
  - unzip3/1
  - usort/1
  - usort/2
  - zip/2
  - zip3/3
  - zipwith/3
  - zipwith3/4
- log_mf_h
  - Top of manual page
  - init/3
  - init/4
- maps
  - Top of manual page
  - filter/2
  - find/2
  - fold/3
  - from_list/1
  - get/2
  - get/3
  - is_key/2
  - iterator/1
  - keys/1
  - map/2
  - merge/2
  - new/0
  - next/1
  - put/3
  - remove/2
  - size/1
  - take/2
  - to_list/1
  - update/3
  - update_with/3
  - update_with/4
  - values/1
  - with/2
  - without/2
- math
  - Top of manual page
  - acos/1
  - acosh/1
  - asin/1
  - asinh/1
  - atan/1
  - atan2/2
  - atanh/1
  - ceil/1
  - cos/1
  - cosh/1
  - erf/1
  - erfc/1
  - exp/1
  - floor/1
  - fmod/2
  - log/1
  - log10/1
  - log2/1
  - pi/0
  - pow/2
  - sin/1
  - sinh/1
  - sqrt/1
  - tan/1
  - tanh/1
- ms_transform
  - Top of manual page
  - format_error/1
  - parse_transform/2
  - transform_from_shell/3
- orddict
  - Top of manual page
  - append/3
  - append_list/3
  - erase/2
  - fetch/2
  - fetch_keys/1
  - filter/2
  - find/2
  - fold/3
  - from_list/1
  - is_empty/1
  - is_key/2
  - map/2
  - merge/3
  - new/0
  - size/1
  - store/3
  - take/2
  - to_list/1
  - update/3
  - update/4
  - update_counter/3
- ordsets
  - Top of manual page
  - add_element/2
  - del_element/2
  - filter/2
  - fold/3
  - from_list/1
  - intersection/1
  - intersection/2
  - is_disjoint/2
  - is_element/2
  - is_empty/1
  - is_set/1
  - is_subset/2
  - new/0
  - size/1
  - subtract/2
  - to_list/1
  - union/1
  - union/2
- pool
  - Top of manual page
  - attach/1
  - get_node/0
  - get_nodes/0
  - pspawn/3
  - pspawn_link/3
  - start/1
  - start/2
  - stop/0
- proc_lib
  - Top of manual page
  - format/1
  - format/2
  - format/3
  - hibernate/3
  - init_ack/1
  - init_ack/2
  - initial_call/1
  - spawn/1
  - spawn/2
  - spawn/3
  - spawn/4
  - spawn_link/1
  - spawn_link/2
  - spawn_link/3
  - spawn_link/4
  - spawn_opt/2
  - spawn_opt/3
  - spawn_opt/4
  - spawn_opt/5
  - start/3
  - start/4
  - start/5
  - start_link/3
  - start_link/4
  - start_link/5
  - start_monitor/3
  - start_monitor/4
  - start_monitor/5
  - stop/1
  - stop/3
  - translate_initial_call/1
- proplists
  - Top of manual page
  - append_values/2
  - compact/1
  - delete/2
  - expand/2
  - get_all_values/2
  - get_bool/2
  - get_keys/1
  - get_value/2
  - get_value/3
  - is_defined/2
  - lookup/2
  - lookup_all/2
  - normalize/2
  - property/1
  - property/2
  - split/2
  - substitute_aliases/2
  - substitute_negations/2
  - unfold/1
- qlc
  - Top of manual page
  - append/1
  - append/2
  - cursor/1
  - cursor/2
  - delete_cursor/1
  - e/1
  - e/2
  - eval/1
  - eval/2
  - fold/3
  - fold/4
  - format_error/1
  - info/1
  - info/2
  - keysort/2
  - keysort/3
  - next_answers/1
  - next_answers/2
  - q/1
  - q/2
  - sort/1
  - sort/2
  - string_to_handle/1
  - string_to_handle/2
  - string_to_handle/3
  - table/2
- queue
  - Top of manual page
  - cons/2
  - daeh/1
  - drop/1
  - drop_r/1
  - filter/2
  - from_list/1
  - get/1
  - get_r/1
  - head/1
  - in/2
  - in_r/2
  - init/1
  - is_empty/1
  - is_queue/1
  - join/2
  - lait/1
  - last/1
  - len/1
  - liat/1
  - member/2
  - new/0
  - out/1
  - out_r/1
  - peek/1
  - peek_r/1
  - reverse/1
  - snoc/2
  - split/2
  - tail/1
  - to_list/1
- rand
  - Top of manual page
  - export_seed/0
  - export_seed_s/1
  - jump/0
  - jump/1
  - normal/0
  - normal/2
  - normal_s/1
  - normal_s/3
  - seed/1
  - seed/2
  - seed_s/1
  - seed_s/2
  - uniform/0
  - uniform/1
  - uniform_real/0
  - uniform_real_s/1
  - uniform_s/1
  - uniform_s/2
- random
  - Top of manual page
  - seed/0
  - seed/1
  - seed/3
  - seed0/0
  - uniform/0
  - uniform/1
  - uniform_s/1
  - uniform_s/2
- re
  - Top of manual page
  - compile/1
  - compile/2
  - inspect/2
  - replace/3
  - replace/4
  - run/2
  - run/3
  - split/2
  - split/3
  - version/0
- sets
  - Top of manual page
  - add_element/2
  - del_element/2
  - filter/2
  - fold/3
  - from_list/1
  - intersection/1
  - intersection/2
  - is_disjoint/2
  - is_element/2
  - is_empty/1
  - is_set/1
  - is_subset/2
  - new/0
  - size/1
  - subtract/2
  - to_list/1
  - union/1
  - union/2
- shell
  - Top of manual page
  - catch_exception/1
  - history/1
  - prompt_func/1
  - results/1
  - start_restricted/1
  - stop_restricted/0
  - strings/1
- shell_default
- shell_docs
  - Top of manual page
  - normalize/1
  - render/2
  - render/3
  - render/4
  - render_callback/2
  - render_callback/3
  - render_callback/4
  - render_type/2
  - render_type/3
  - render_type/4
  - validate/1
- slave
  - Top of manual page
  - pseudo/1
  - pseudo/2
  - relay/1
  - start/1
  - start/2
  - start/3
  - start_link/1
  - start_link/2
  - start_link/3
  - stop/1
- sofs
  - Top of manual page
  - a_function/1
  - a_function/2
  - canonical_relation/1
  - composite/2
  - constant_function/2
  - converse/1
  - difference/2
  - digraph_to_family/1
  - digraph_to_family/2
  - domain/1
  - drestriction/2
  - drestriction/3
  - empty_set/0
  - extension/3
  - family/1
  - family/2
  - family_difference/2
  - family_domain/1
  - family_field/1
  - family_intersection/1
  - family_intersection/2
  - family_projection/2
  - family_range/1
  - family_specification/2
  - family_to_digraph/1
  - family_to_digraph/2
  - family_to_relation/1
  - family_union/1
  - family_union/2
  - field/1
  - from_external/2
  - from_sets/1
  - from_term/1
  - from_term/2
  - image/2
  - intersection/1
  - intersection/2
  - intersection_of_family/1
  - inverse/1
  - inverse_image/2
  - is_a_function/1
  - is_disjoint/2
  - is_empty_set/1
  - is_equal/2
  - is_set/1
  - is_sofs_set/1
  - is_subset/2
  - is_type/1
  - join/4
  - multiple_relative_product/2
  - no_elements/1
  - partition/1
  - partition/2
  - partition/3
  - partition_family/2
  - product/1
  - product/2
  - projection/2
  - range/1
  - relation/1
  - relation/2
  - relation_to_family/1
  - relative_product/1
  - relative_product/2
  - relative_product1/2
  - restriction/2
  - restriction/3
  - set/1
  - set/2
  - specification/2
  - strict_relation/1
  - substitution/2
  - symdiff/2
  - symmetric_partition/2
  - to_external/1
  - to_sets/1
  - type/1
  - union/1
  - union/2
  - union_of_family/1
  - weak_relation/1
- string
  - Top of manual page
  - casefold/1
  - centre/2
  - centre/3
  - chars/2
  - chars/3
  - chomp/1
  - chr/2
  - concat/2
  - copies/2
  - cspan/2
  - equal/2
  - equal/3
  - equal/4
  - find/2
  - find/3
  - is_empty/1
  - join/2
  - left/2
  - left/3
  - len/1
  - length/1
  - lexemes/2
  - lowercase/1
  - next_codepoint/1
  - next_grapheme/1
  - nth_lexeme/3
  - pad/2
  - pad/3
  - pad/4
  - prefix/2
  - rchr/2
  - replace/3
  - replace/4
  - reverse/1
  - right/2
  - right/3
  - rstr/2
  - slice/2
  - slice/3
  - span/2
  - split/2
  - split/3
  - str/2
  - strip/1
  - strip/2
  - strip/3
  - sub_string/2
  - sub_string/3
  - sub_word/2
  - sub_word/3
  - substr/2
  - substr/3
  - take/2
  - take/3
  - take/4
  - titlecase/1
  - to_float/1
  - to_graphemes/1
  - to_integer/1
  - to_lower/1
  - to_upper/1
  - tokens/2
  - trim/1
  - trim/2
  - trim/3
  - uppercase/1
  - words/1
  - words/2
- supervisor
  - Top of manual page
  - check_childspecs/1
  - count_children/1
  - delete_child/2
  - get_childspec/2
  - restart_child/2
  - start_child/2
  - start_link/2
  - start_link/3
  - terminate_child/2
  - which_children/1
  - Module:init/1
- supervisor_bridge
  - Top of manual page
  - start_link/2
  - start_link/3
  - Module:init/1
  - Module:terminate/2
- sys
  - Top of manual page
  - change_code/4
  - change_code/5
  - debug_options/1
  - get_debug/3
  - get_log/1
  - get_state/1
  - get_state/2
  - get_status/1
  - get_status/2
  - handle_debug/4
  - handle_system_msg/6
  - install/2
  - install/3
  - log/2
  - log/3
  - log_to_file/2
  - log_to_file/3
  - no_debug/1
  - no_debug/2
  - print_log/1
  - remove/2
  - remove/3
  - replace_state/2
  - replace_state/3
  - resume/1
  - resume/2
  - statistics/2
  - statistics/3
  - suspend/1
  - suspend/2
  - terminate/2
  - terminate/3
  - trace/2
  - trace/3
  - Module:system_code_change/4
  - Module:system_continue/3
  - Module:system_get_state/1
  - Module:system_replace_state/2
  - Module:system_terminate/4
- timer
  - Top of manual page
  - apply_after/4
  - apply_interval/4
  - cancel/1
  - exit_after/2
  - exit_after/3
  - hms/3
  - hours/1
  - kill_after/1
  - kill_after/2
  - minutes/1
  - now_diff/2
  - seconds/1
  - send_after/2
  - send_after/3
  - send_interval/2
  - send_interval/3
  - sleep/1
  - start/0
  - tc/1
  - tc/2
  - tc/3
- unicode
  - Top of manual page
  - bom_to_encoding/1
  - characters_to_binary/1
  - characters_to_binary/2
  - characters_to_binary/3
  - characters_to_list/1
  - characters_to_list/2
  - characters_to_nfc_binary/1
  - characters_to_nfc_list/1
  - characters_to_nfd_binary/1
  - characters_to_nfd_list/1
  - characters_to_nfkc_binary/1
  - characters_to_nfkc_list/1
  - characters_to_nfkd_binary/1
  - characters_to_nfkd_list/1
  - encoding_to_bom/1
- uri_string
  - Top of manual page
  - compose_query/1
  - compose_query/2
  - dissect_query/1
  - normalize/1
  - normalize/2
  - parse/1
  - recompose/1
  - resolve/2
  - resolve/3
  - transcode/2
- win32reg
  - Top of manual page
  - change_key/2
  - change_key_create/2
  - close/1
  - current_key/1
  - delete_key/1
  - delete_value/2
  - expand/1
  - format_error/1
  - open/1
  - set_value/3
  - sub_keys/1
  - value/2
  - values/1
- zip
  - Top of manual page
  - create/2
  - create/3
  - extract/1
  - extract/2
  - foldl/3
  - list_dir/1
  - list_dir/2
  - t/1
  - table/1
  - table/2
  - tt/1
  - unzip/1
  - unzip/2
  - zip/2
  - zip/3
  - zip_close/1
  - zip_get/1
  - zip_get/2
  - zip_list_dir/1
  - zip_open/1
  - zip_open/2

# ms_transform

### Module

ms_transform

### Module Summary

A parse transformation that translates fun syntax into match specifications.

### Description

This module provides the parse transformation that makes calls to ets and dbg:fun2ms/1 translate into literal match specifications. It also provides the back end for the same functions when called from the Erlang shell.

The translation from funs to match specifications is accessed through the two "pseudo functions" ets:fun2ms/1 and dbg:fun2ms/1.

As everyone trying to use ets:select/2 or dbg seems to end up reading this manual page, this description is an introduction to the concept of match specifications.

Read the whole manual page if it is the first time you are using the transformations.

Match specifications are used more or less as filters. They resemble usual Erlang matching in a list comprehension or in a fun used with lists:foldl/3, and so on. However, the syntax of pure match specifications is awkward, as they are made up purely by Erlang terms, and the language has no syntax to make the match specifications more readable.

As the execution and structure of the match specifications are like that of a fun, it is more straightforward to write it using the familiar fun syntax and to have that translated into a match specification automatically. A real fun is clearly more powerful than the match specifications allow, but bearing the match specifications in mind, and what they can do, it is still more convenient to write it all as a fun. This module contains the code that translates the fun syntax into match specification terms.

### Example 1

Using ets:select/2 and a match specification, one can filter out rows of a table and construct a list of tuples containing relevant parts of the data in these rows. One can use ets:foldl/3 instead, but the ets:select/2 call is far more efficient. Without the translation provided by ms_transform, one must struggle with writing match specifications terms to accommodate this.

Consider a simple table of employees:

    -record(emp, {empno,     %Employee number as a string, the key
                  surname,   %Surname of the employee
                  givenname, %Given name of employee
                  dept,      %Department, one of {dev,sales,prod,adm}
                  empyear}). %Year the employee was employed

We create the table using:

    ets:new(emp_tab, [{keypos,#emp.empno},named_table,ordered_set]).

We fill the table with randomly chosen data:

    [{emp,"011103","Black","Alfred",sales,2000},
     {emp,"041231","Doe","John",prod,2001},
     {emp,"052341","Smith","John",dev,1997},
     {emp,"076324","Smith","Ella",sales,1995},
     {emp,"122334","Weston","Anna",prod,2002},
     {emp,"535216","Chalker","Samuel",adm,1998},
     {emp,"789789","Harrysson","Joe",adm,1996},
     {emp,"963721","Scott","Juliana",dev,2003},
     {emp,"989891","Brown","Gabriel",prod,1999}]

Assuming that we want the employee numbers of everyone in the sales department, there are several ways.

ets:match/2 can be used:

    1> ets:match(emp_tab, {'_', '$1', '_', '_', sales, '_'}).
    [["011103"],["076324"]]

ets:match/2 uses a simpler type of match specification, but it is still unreadable, and one has little control over the returned result. It is always a list of lists.

ets:foldl/3 or ets:foldr/3 can be used to avoid the nested lists:

    ets:foldr(fun(#emp{empno = E, dept = sales},Acc) -> [E | Acc];
                 (_,Acc) -> Acc
              end,
              [],
              emp_tab).

The result is ["011103","076324"]. The fun is straightforward, so the only problem is that all the data from the table must be transferred from the table to the calling process for filtering. That is inefficient compared to the ets:match/2 call where the filtering can be done "inside" the emulator and only the result is transferred to the process.

Consider a "pure" ets:select/2 call that does what ets:foldr does:

    ets:select(emp_tab, [{#emp{empno = '$1', dept = sales, _='_'},[],['$1']}]).

Although the record syntax is used, it is still hard to read and even harder to write. The first element of the tuple, #emp{empno = '$1', dept = sales, _='_'}, tells what to match. Elements not matching this are not returned, as in the ets:match/2 example. The second element, the empty list, is a list of guard expressions, which we do not need. The third element is the list of expressions constructing the return value (in ETS this is almost always a list containing one single term). In our case '$1' is bound to the employee number in the head (first element of the tuple), and hence the employee number is returned. The result is ["011103","076324"], as in the ets:foldr/3 example, but the result is retrieved much more efficiently in terms of execution speed and memory consumption.

Using ets:fun2ms/1, we can combine the ease of use of the ets:foldr/3 and the efficiency of the pure ets:select/2 example:

    -include_lib("stdlib/include/ms_transform.hrl").

    ets:select(emp_tab, ets:fun2ms(
                          fun(#emp{empno = E, dept = sales}) ->
                                  E
                          end)).

This example requires no special knowledge of match specifications to understand. The head of the fun matches what you want to filter out and the body returns what you want returned. As long as the fun can be kept within the limits of the match specifications, there is no need to transfer all table data to the process for filtering as in the ets:foldr/3 example. It is easier to read than the ets:foldr/3 example, as the select call in itself discards anything that does not match, while the fun of the ets:foldr/3 call needs to handle both the elements matching and the ones not matching.

In the ets:fun2ms/1 example above, it is needed to include ms_transform.hrl in the source code, as this is what triggers the parse transformation of the ets:fun2ms/1 call to a valid match specification. This also implies that the transformation is done at compile time (except when called from the shell) and therefore takes no resources in runtime. That is, although you use the more intuitive fun syntax, it gets as efficient in runtime as writing match specifications by hand.

### Example 2

Assume that we want to get all the employee numbers of employees hired before year 2000. Using ets:match/2 is not an alternative here, as relational operators cannot be expressed there. Once again, ets:foldr/3 can do it (slowly, but correct):

    ets:foldr(fun(#emp{empno = E, empyear = Y},Acc) when Y < 2000 -> [E | Acc];
                      (_,Acc) -> Acc
              end,
              [],
              emp_tab).

The result is ["052341","076324","535216","789789","989891"], as expected. The equivalent expression using a handwritten match specification would look like this:

    ets:select(emp_tab, [{#emp{empno = '$1', empyear = '$2', _='_'},
                         [{'<', '$2', 2000}],
                         ['$1']}]).

This gives the same result. [{'<', '$2', 2000}] is in the guard part and therefore discards anything that does not have an empyear (bound to '$2' in the head) less than 2000, as the guard in the foldr/3 example.

We write it using ets:fun2ms/1:

    -include_lib("stdlib/include/ms_transform.hrl").

    ets:select(emp_tab, ets:fun2ms(
                          fun(#emp{empno = E, empyear = Y}) when Y < 2000 ->
                               E
                          end)).

### Example 3

Assume that we want the whole object matching instead of only one element. One alternative is to assign a variable to every part of the record and build it up once again in the body of the fun, but the following is easier:

    ets:select(emp_tab, ets:fun2ms(
                          fun(Obj = #emp{empno = E, empyear = Y})
                             when Y < 2000 ->
                                  Obj
                          end)).

As in ordinary Erlang matching, you can bind a variable to the whole matched object using a "match inside the match", that is, a =. Unfortunately in funs translated to match specifications, it is allowed only at the "top-level", that is, matching the whole object arriving to be matched into a separate variable. If you are used to writing match specifications by hand, we mention that variable A is simply translated into '$_'. Alternatively, pseudo function object/0 also returns the whole matched object, see section Warnings and Restrictions.

### Example 4

This example concerns the body of the fun. Assume that all employee numbers beginning with zero (0) must be changed to begin with one (1) instead, and that we want to create the list [{<Old empno>,<New empno>}]:

    ets:select(emp_tab, ets:fun2ms(
                          fun(#emp{empno = [$0 | Rest] }) ->
                                  {[$0|Rest],[$1|Rest]}
                          end)).

This query hits the feature of partially bound keys in table type ordered_set, so that not the whole table needs to be searched, only the part containing keys beginning with 0 is looked into.

### Example 5

The fun can have many clauses. Assume that we want to do the following:

- If an employee started before 1997, return the tuple {inventory, <employee number>}.

- If an employee started 1997 or later, but before 2001, return {rookie, <employee number>}.

- For all other employees, return {newbie, <employee number>}, except for those named Smith as they would be affronted by anything other than the tag guru and that is also what is returned for their numbers: {guru, <employee number>}.

This is accomplished as follows:

    ets:select(emp_tab, ets:fun2ms(
                          fun(#emp{empno = E, surname = "Smith" }) ->
                                  {guru,E};
                             (#emp{empno = E, empyear = Y}) when Y < 1997  ->
                                  {inventory, E};
                             (#emp{empno = E, empyear = Y}) when Y > 2001  ->
                                  {newbie, E};
                             (#emp{empno = E, empyear = Y}) -> % 1997 -- 2001
                                  {rookie, E}
                          end)).

The result is as follows:

    [{rookie,"011103"},
     {rookie,"041231"},
     {guru,"052341"},
     {guru,"076324"},
     {newbie,"122334"},
     {rookie,"535216"},
     {inventory,"789789"},
     {newbie,"963721"},
     {rookie,"989891"}]

### Useful BIFs

What more can you do? A simple answer is: see the documentation of match specifications in ERTS User's Guide. However, the following is a brief overview of the most useful "built-in functions" that you can use when the fun is to be translated into a match specification by ets:fun2ms/1. It is not possible to call other functions than those allowed in match specifications. No "usual" Erlang code can be executed by the fun that is translated by ets:fun2ms/1. The fun is limited exactly to the power of the match specifications, which is unfortunate, but the price one must pay for the execution speed of ets:select/2 compared to ets:foldl/foldr.

The head of the fun is a head matching (or mismatching) one parameter, one object of the table we select from. The object is always a single variable (can be _) or a tuple, as ETS, Dets, and Mnesia tables include that. The match specification returned by ets:fun2ms/1 can be used with dets:select/2 and mnesia:select/2, and with ets:select/2. The use of = in the head is allowed (and encouraged) at the top-level.

The guard section can contain any guard expression of Erlang. The following is a list of BIFs and expressions:

- Type tests: is_atom, is_float, is_integer, is_list, is_number, is_pid, is_port, is_reference, is_tuple, is_binary, is_function, is_record

- Boolean operators: not, and, or, andalso, orelse

- Relational operators: >, >=, <, =<, =:=, ==, =/=, /=

- Arithmetics: +, -, *, div, rem

- Bitwise operators: band, bor, bxor, bnot, bsl, bsr

- The guard BIFs: abs, element, hd, length, node, round, size, tl, trunc, self

Contrary to the fact with "handwritten" match specifications, the is_record guard works as in ordinary Erlang code.

Semicolons (;) in guards are allowed, the result is (as expected) one "match specification clause" for each semicolon-separated part of the guard. The semantics is identical to the Erlang semantics.

The body of the fun is used to construct the resulting value. When selecting from tables, one usually construct a suiting term here, using ordinary Erlang term construction, like tuple parentheses, list brackets, and variables matched out in the head, possibly with the occasional constant. Whatever expressions are allowed in guards are also allowed here, but no special functions exist except object and bindings (see further down), which returns the whole matched object and all known variable bindings, respectively.

The dbg variants of match specifications have an imperative approach to the match specification body, the ETS dialect has not. The fun body for ets:fun2ms/1 returns the result without side effects. As matching (=) in the body of the match specifications is not allowed (for performance reasons) the only thing left, more or less, is term construction.

### Example with dbg

This section describes the slightly different match specifications translated by dbg:fun2ms/1.

The same reasons for using the parse transformation apply to dbg, maybe even more, as filtering using Erlang code is not a good idea when tracing (except afterwards, if you trace to file). The concept is similar to that of ets:fun2ms/1 except that you usually use it directly from the shell (which can also be done with ets:fun2ms/1).

The following is an example module to trace on:

    -module(toy).

    -export([start/1, store/2, retrieve/1]).

    start(Args) ->
        toy_table = ets:new(toy_table, Args).

    store(Key, Value) ->
        ets:insert(toy_table, {Key,Value}).

    retrieve(Key) ->
        [{Key, Value}] = ets:lookup(toy_table, Key),
        Value.

During model testing, the first test results in {badmatch,16} in {toy,start,1}, why?

We suspect the ets:new/2 call, as we match hard on the return value, but want only the particular new/2 call with toy_table as first parameter. So we start a default tracer on the node:

    1> dbg:tracer().
    {ok,<0.88.0>}

We turn on call tracing for all processes, we want to make a pretty restrictive trace pattern, so there is no need to call trace only a few processes (usually it is not):

    2> dbg:p(all,call).
    {ok,[{matched,nonode@nohost,25}]}

We specify the filter, we want to view calls that resemble ets:new(toy_table, <something>):

    3> dbg:tp(ets,new,dbg:fun2ms(fun([toy_table,_]) -> true end)).
    {ok,[{matched,nonode@nohost,1},{saved,1}]}

As can be seen, the fun used with dbg:fun2ms/1 takes a single list as parameter instead of a single tuple. The list matches a list of the parameters to the traced function. A single variable can also be used. The body of the fun expresses, in a more imperative way, actions to be taken if the fun head (and the guards) matches. true is returned here, only because the body of a fun cannot be empty. The return value is discarded.

The following trace output is received during test:

    (<0.86.0>) call ets:new(toy_table, [ordered_set])

Assume that we have not found the problem yet, and want to see what ets:new/2 returns. We use a slightly different trace pattern:

    4> dbg:tp(ets,new,dbg:fun2ms(fun([toy_table,_]) -> return_trace() end)).

The following trace output is received during test:

    (<0.86.0>) call ets:new(toy_table,[ordered_set])
    (<0.86.0>) returned from ets:new/2 -> 24

The call to return_trace results in a trace message when the function returns. It applies only to the specific function call triggering the match specification (and matching the head/guards of the match specification). This is by far the most common call in the body of a dbg match specification.

The test now fails with {badmatch,24} because the atom toy_table does not match the number returned for an unnamed table. So, the problem is found, the table is to be named, and the arguments supplied by the test program do not include named_table. We rewrite the start function:

    start(Args) ->
        toy_table = ets:new(toy_table, [named_table|Args]).

With the same tracing turned on, the following trace output is received:

    (<0.86.0>) call ets:new(toy_table,[named_table,ordered_set])
    (<0.86.0>) returned from ets:new/2 -> toy_table

Assume that the module now passes all testing and goes into the system. After a while, it is found that table toy_table grows while the system is running and that there are many elements with atoms as keys. We expected only integer keys and so does the rest of the system, but clearly not the entire system. We turn on call tracing and try to see calls to the module with an atom as the key:

    1> dbg:tracer().
    {ok,<0.88.0>}
    2> dbg:p(all,call).
    {ok,[{matched,nonode@nohost,25}]}
    3> dbg:tpl(toy,store,dbg:fun2ms(fun([A,_]) when is_atom(A) -> true end)).
    {ok,[{matched,nonode@nohost,1},{saved,1}]}

We use dbg:tpl/3 to ensure to catch local calls (assume that the module has grown since the smaller version and we are unsure if this inserting of atoms is not done locally). When in doubt, always use local call tracing.

Assume that nothing happens when tracing in this way. The function is never called with these parameters. We conclude that someone else (some other module) is doing it and realize that we must trace on ets:insert/2 and want to see the calling function. The calling function can be retrieved using the match specification function caller. To get it into the trace message, the match specification function message must be used. The filter call looks like this (looking for calls to ets:insert/2):

    4> dbg:tpl(ets,insert,dbg:fun2ms(fun([toy_table,{A,_}]) when is_atom(A) ->
                                        message(caller())
                                      end)).
    {ok,[{matched,nonode@nohost,1},{saved,2}]}

The caller is now displayed in the "additional message" part of the trace output, and the following is displayed after a while:

    (<0.86.0>) call ets:insert(toy_table,{garbage,can}) ({evil_mod,evil_fun,2})

You have realized that function evil_fun of the evil_mod module, with arity 2, is causing all this trouble.

This example illustrates the most used calls in match specifications for dbg. The other, more esoteric, calls are listed and explained in Match specifications in Erlang in ERTS User's Guide, as they are beyond the scope of this description.

### Warnings and Restrictions

The following warnings and restrictions apply to the funs used in with ets:fun2ms/1 and dbg:fun2ms/1.

Warning

To use the pseudo functions triggering the translation, ensure to include the header file ms_transform.hrl in the source code. Failure to do so possibly results in runtime errors rather than compile time, as the expression can be valid as a plain Erlang program without translation.

Warning

The fun must be literally constructed inside the parameter list to the pseudo functions. The fun cannot be bound to a variable first and then passed to ets:fun2ms/1 or dbg:fun2ms/1. For example, ets:fun2ms(fun(A) -> A end) works, but not F = fun(A) -> A end, ets:fun2ms(F). The latter results in a compile-time error if the header is included, otherwise a runtime error.

Many restrictions apply to the fun that is translated into a match specification. To put it simple: you cannot use anything in the fun that you cannot use in a match specification. This means that, among others, the following restrictions apply to the fun itself:

- Functions written in Erlang cannot be called, neither can local functions, global functions, or real funs.

- Everything that is written as a function call is translated into a match specification call to a built-in function, so that the call is_list(X) is translated to {'is_list', '$1'} ('$1' is only an example, the numbering can vary). If one tries to call a function that is not a match specification built-in, it causes an error.

- Variables occurring in the head of the fun are replaced by match specification variables in the order of occurrence, so that fragment fun({A,B,C}) is replaced by {'$1', '$2', '$3'}, and so on. Every occurrence of such a variable in the match specification is replaced by a match specification variable in the same way, so that the fun fun({A,B}) when is_atom(A) -> B end is translated into [{{'$1','$2'},[{is_atom,'$1'}],['$2']}].

- Variables that are not included in the head are imported from the environment and made into match specification const expressions. Example from the shell:

      1> X = 25.
      25
      2> ets:fun2ms(fun({A,B}) when A > X -> B end).
      [{{'$1','$2'},[{'>','$1',{const,25}}],['$2']}]

- Matching with = cannot be used in the body. It can only be used on the top-level in the head of the fun. Example from the shell again:

      1> ets:fun2ms(fun({A,[B|C]} = D) when A > B -> D end).
      [{{'$1',['$2'|'$3']},[{'>','$1','$2'}],['$_']}]
      2> ets:fun2ms(fun({A,[B|C]=D}) when A > B -> D end).
      Error: fun with head matching ('=' in head) cannot be translated into
      match_spec
      {error,transform_error}
      3> ets:fun2ms(fun({A,[B|C]}) when A > B -> D = [B|C], D end).
      Error: fun with body matching ('=' in body) is illegal as match_spec
      {error,transform_error}

  All variables are bound in the head of a match specification, so the translator cannot allow multiple bindings. The special case when matching is done on the top-level makes the variable bind to '$_' in the resulting match specification. It is to allow a more natural access to the whole matched object. Pseudo function object() can be used instead, see below.

  The following expressions are translated equally:

      ets:fun2ms(fun({a,_} = A) -> A end).
      ets:fun2ms(fun({a,_}) -> object() end).

- The special match specification variables '$_' and '$*' can be accessed through the pseudo functions object() (for '$_') and bindings() (for '$*'). As an example, one can translate the following ets:match_object/2 call to a ets:select/2 call:

      ets:match_object(Table, {'$1',test,'$2'}).

  This is the same as:

      ets:select(Table, ets:fun2ms(fun({A,test,B}) -> object() end)).

  In this simple case, the former expression is probably preferable in terms of readability.

  The ets:select/2 call conceptually looks like this in the resulting code:

      ets:select(Table, [{{'$1',test,'$2'},[],['$_']}]).

  Matching on the top-level of the fun head can be a more natural way to access '$_', see above.

- Term constructions/literals are translated as much as is needed to get them into valid match specification. This way tuples are made into match specification tuple constructions (a one element tuple containing the tuple) and constant expressions are used when importing variables from the environment. Records are also translated into plain tuple constructions, calls to element, and so on. The guard test is_record/2 is translated into match specification code using the three parameter version that is built into match specification, so that is_record(A,t) is translated into {is_record,'$1',t,5} if the record size of record type t is 5.

- Language constructions such as case, if, and catch that are not present in match specifications are not allowed.

- If header file ms_transform.hrl is not included, the fun is not translated, which can result in a runtime error (depending on whether the fun is valid in a pure Erlang context).

  Ensure that the header is included when using ets and dbg:fun2ms/1 in compiled code.

- If pseudo function triggering the translation is ets:fun2ms/1, the head of the fun must contain a single variable or a single tuple. If the pseudo function is dbg:fun2ms/1, the head of the fun must contain a single variable or a single list.

The translation from funs to match specifications is done at compile time, so runtime performance is not affected by using these pseudo functions.

For more information about match specifications, see the Match specifications in Erlang in ERTS User's Guide.

### Exports

format_error(Error) -> Chars |

### Types

Error = {error, module(), term()}
Chars = io_lib:chars()

Takes an error code returned by one of the other functions in the module and creates a textual description of the error.

parse_transform(Forms, Options) -> Forms2 | Errors | Warnings |

### Types

Forms = Forms2 = [erl_parse:abstract_form() | erl_parse:form_info()]
Options = term()
Option list, required but not used.
Errors = {error, ErrInfo :: [tuple()], WarnInfo :: []}
Warnings = {warning, Forms2, WarnInfo :: [tuple()]}

Implements the transformation at compile time. This function is called by the compiler to do the source code transformation if and when header file ms_transform.hrl is included in the source code.

For information about how to use this parse transformation, see ets and dbg:fun2ms/1.

For a description of match specifications, see section Match Specification in Erlang in ERTS User's Guide.

transform_from_shell(Dialect, Clauses, BoundEnvironment) -> term() |

### Types

Dialect = ets | dbg
Clauses = [erl_parse:abstract_clause()]
BoundEnvironment = erl_eval:binding_struct()
List of variable bindings in the shell environment.

Implements the transformation when the fun2ms/1 functions are called from the shell. In this case, the abstract form is for one single fun (parsed by the Erlang shell). All imported variables are to be in the key-value list passed as BoundEnvironment. The result is a term, normalized, that is, not in abstract format.