User's Guide
Reference Manual
Release Notes
PDF
Top

Erlang Interface
Reference Manual
Version 3.8.1

Expand All
Contract All

Table of Contents

- ei
  - Top of manual page
  - ei_set_compat_rel()
  - ei_encode_version()
  - ei_x_encode_version()
  - ei_encode_long()
  - ei_x_encode_long()
  - ei_encode_ulong()
  - ei_x_encode_ulong()
  - ei_encode_longlong()
  - ei_x_encode_longlong()
  - ei_encode_ulonglong()
  - ei_x_encode_ulonglong()
  - ei_encode_bignum()
  - ei_x_encode_bignum()
  - ei_encode_double()
  - ei_x_encode_double()
  - ei_encode_boolean()
  - ei_x_encode_boolean()
  - ei_encode_char()
  - ei_x_encode_char()
  - ei_encode_string()
  - ei_encode_string_len()
  - ei_x_encode_string()
  - ei_x_encode_string_len()
  - ei_encode_atom()
  - ei_encode_atom_len()
  - ei_x_encode_atom()
  - ei_x_encode_atom_len()
  - ei_encode_atom_as()
  - ei_encode_atom_len_as()
  - ei_x_encode_atom_as()
  - ei_x_encode_atom_len_as()
  - ei_encode_binary()
  - ei_x_encode_binary()
  - ei_encode_pid()
  - ei_x_encode_pid()
  - ei_encode_fun()
  - ei_x_encode_fun()
  - ei_encode_port()
  - ei_x_encode_port()
  - ei_encode_ref()
  - ei_x_encode_ref()
  - ei_encode_term()
  - ei_x_encode_term()
  - ei_encode_trace()
  - ei_x_encode_trace()
  - ei_encode_tuple_header()
  - ei_x_encode_tuple_header()
  - ei_encode_list_header()
  - ei_x_encode_list_header()
  - ei_encode_empty_list()
  - ei_x_encode_empty_list()
  - ei_encode_map_header()
  - ei_x_encode_map_header()
  - ei_get_type()
  - ei_decode_version()
  - ei_decode_long()
  - ei_decode_ulong()
  - ei_decode_longlong()
  - ei_decode_ulonglong()
  - ei_decode_bignum()
  - ei_decode_double()
  - ei_decode_boolean()
  - ei_decode_char()
  - ei_decode_string()
  - ei_decode_atom()
  - ei_decode_atom_as()
  - ei_decode_binary()
  - ei_decode_fun()
  - free_fun()
  - ei_decode_pid()
  - ei_decode_port()
  - ei_decode_ref()
  - ei_decode_trace()
  - ei_decode_tuple_header()
  - ei_decode_list_header()
  - ei_decode_map_header()
  - ei_decode_ei_term()
  - ei_decode_term()
  - ei_print_term()
  - ei_s_print_term()
  - ei_x_format()
  - ei_x_format_wo_ver()
  - ei_x_new()
  - ei_x_new_with_version()
  - ei_x_free()
  - ei_x_append()
  - ei_x_append_buf()
  - ei_skip_term()
- ei_connect
  - Top of manual page
  - ei_connect_init()
  - ei_connect_xinit()
  - ei_connect()
  - ei_xconnect()
  - ei_connect_tmo()
  - ei_xconnect_tmo()
  - ei_receive()
  - ei_receive_tmo()
  - ei_receive_msg()
  - ei_xreceive_msg()
  - ei_receive_msg_tmo()
  - ei_xreceive_msg_tmo()
  - ei_receive_encoded()
  - ei_receive_encoded_tmo()
  - ei_send()
  - ei_send_tmo()
  - ei_send_encoded()
  - ei_send_encoded_tmo()
  - ei_reg_send()
  - ei_reg_send_tmo()
  - ei_send_reg_encoded()
  - ei_send_reg_encoded_tmo()
  - ei_rpc()
  - ei_rpc_to()
  - ei_rpc_from()
  - ei_publish()
  - ei_publish_tmo()
  - ei_accept()
  - ei_accept_tmo()
  - ei_unpublish()
  - ei_unpublish_tmo()
  - ei_thisnodename()
  - ei_thishostname()
  - ei_thisalivename()
  - ei_self()
  - *ei_gethostbyname()
  - *ei_gethostbyaddr()
  - *ei_gethostbyname_r()
  - *ei_gethostbyaddr_r()
  - ei_get_tracelevel()
  - ei_set_tracelevel()
- registry
  - Top of manual page
  - ei_reg_open()
  - ei_reg_resize()
  - ei_reg_close()
  - ei_reg_setival()
  - ei_reg_setfval()
  - ei_reg_setsval()
  - ei_reg_setpval()
  - ei_reg_setval()
  - ei_reg_getival()
  - ei_reg_getfval()
  - ei_reg_getsval()
  - ei_reg_getpval()
  - ei_reg_getval()
  - ei_reg_markdirty()
  - ei_reg_delete()
  - ei_reg_stat()
  - ei_reg_tabstat()
  - ei_reg_dump()
  - ei_reg_restore()
  - ei_reg_purge()
- erl_connect
  - Top of manual page
  - erl_connect_init()
  - erl_connect_xinit()
  - erl_connect()
  - erl_xconnect()
  - erl_close_connection()
  - erl_receive()
  - erl_receive_msg()
  - erl_xreceive_msg()
  - erl_send()
  - erl_reg_send()
  - erl_rpc()
  - erl_rpc_to()
  - erl_rpc_from()
  - erl_publish()
  - erl_accept()
  - erl_thiscookie()
  - erl_thisnodename()
  - erl_thishostname()
  - erl_thisalivename()
  - erl_thiscreation()
  - erl_unpublish()
  - *erl_gethostbyname()
  - *erl_gethostbyaddr()
  - *erl_gethostbyname_r()
  - *erl_gethostbyaddr_r()
- erl_error
  - Top of manual page
  - erl_err_msg()
  - erl_err_quit()
  - erl_err_ret()
  - erl_err_sys()
  - erl_errno()
- erl_eterm
  - Top of manual page
  - erl_cons()
  - erl_copy_term()
  - erl_element()
  - erl_init()
  - erl_hd()
  - erl_iolist_to_binary()
  - erl_iolist_to_string()
  - erl_iolist_length()
  - erl_length()
  - erl_mk_atom()
  - erl_mk_binary()
  - erl_mk_empty_list()
  - erl_mk_estring()
  - erl_mk_float()
  - erl_mk_int()
  - erl_mk_list()
  - erl_mk_pid()
  - erl_mk_port()
  - erl_mk_ref()
  - erl_mk_long_ref()
  - erl_mk_string()
  - erl_mk_tuple()
  - erl_mk_uint()
  - erl_mk_var()
  - erl_print_term()
  - erl_set_compat_rel()
  - erl_size()
  - erl_tl()
  - erl_var_content()
- erl_format
  - Top of manual page
  - erl_format()
  - erl_match()
- erl_global
  - Top of manual page
  - erl_global_names()
  - erl_global_register()
  - erl_global_unregister()
  - erl_global_whereis()
- erl_malloc
  - Top of manual page
  - erl_alloc_eterm()
  - erl_eterm_release()
  - erl_eterm_statistics()
  - erl_free_array()
  - erl_free_term()
  - erl_free_compound()
  - erl_malloc()
  - erl_free()
- erl_marshal
  - Top of manual page
  - erl_compare_ext()
  - erl_decode()
  - erl_decode_buf()
  - erl_encode()
  - erl_encode_buf()
  - erl_ext_size()
  - erl_ext_type()
  - erl_peek_ext()
  - erl_term_len()
- erl_call

# erl_format

### C LIBRARY

erl_format

### LIBRARY SUMMARY

Create and Match Erlang Terms

### DESCRIPTION

This module contains two routines - one general function for creating Erlang terms and one for pattern matching Erlang terms.

### EXPORTS

ETERM *erl_format(FormatStr, ... )

Types:

char *FormatStr;

This is a general function for creating Erlang terms using a format specifier and a corresponding set of arguments, much in the way printf() works.

FormatStr is a format specification string. The set of valid format specifiers is as follows:

- ~i - Integer

- ~f - Floating point

- ~a - Atom

- ~s - String

- ~w - Arbitrary Erlang term

For each format specifier that appears in FormatStr, there must be a corresponding argument following FormatStr. An Erlang term is built according to the FormatStr with values and Erlang terms substituted from the corresponding arguments and according to the individual format specifiers. For example:

    erl_format("[{name,~a},{age,~i},{data,~w}]",
               "madonna",
               21,
               erl_format("[{adr,~s,~i}]","E-street",42));

This will create an (ETERM *) structure corresponding to the Erlang term: [{name,madonna},{age,21},{data,[{adr,"E-street",42}]}]

The function returns an Erlang term, or NULL if FormatStr does not describe a valid Erlang term.

int erl_match(Pattern, Term)

Types:

ETERM *Pattern,*Term;

This function is used to perform pattern matching similar to that done in Erlang. Refer to an Erlang manual for matching rules and more examples.

Pattern is an Erlang term, possibly containing unbound variables.

Term is an Erlang term that we wish to match against Pattern.

Term and Pattern are compared, and any unbound variables in Pattern are bound to corresponding values in Term.

If Term and Pattern can be matched, the function returns a non-zero value and binds any unbound variables in Pattern. If Term Pattern do not match, the function returns 0. For example:

    ETERM *term, *pattern, *pattern2;
    term1    = erl_format("{14,21}");
    term2    = erl_format("{19,19}");
    pattern1 = erl_format("{A,B}");
    pattern2 = erl_format("{F,F}");
    if (erl_match(pattern1, term1)) {
      /* match succeeds:
       * A gets bound to 14,
       * B gets bound to 21
       */
      ...
    }
    if (erl_match(pattern2, term1)) {
      /* match fails because F cannot be
       * bound to two separate values, 14 and 21
       */
      ...
    }
    if (erl_match(pattern2, term2)) {
      /* match succeeds and F gets bound to 19 */
      ...
    }

erl_var_content() can be used to retrieve the content of any variables bound as a result of a call to erl_match().