1erl_format(3)                 C Library Functions                erl_format(3)
2
3
4

NAME

6       erl_format - Create and match Erlang terms.
7

DESCRIPTION

9       This  module  contains  two routines: one general function for creating
10       Erlang terms and one for pattern matching Erlang terms.
11

EXPORTS

13       ETERM *erl_format(FormatStr, ...)
14
15              Types:
16
17                 char *FormatStr;
18
19              A general function for creating  Erlang  terms  using  a  format
20              specifier  and a corresponding set of arguments, much in the way
21              printf() works.
22
23              FormatStr is a format specification  string.  The  valid  format
24              specifiers are as follows:
25
26                * ~i - Integer
27
28                * ~f - Floating point
29
30                * ~a - Atom
31
32                * ~s - String
33
34                * ~w - Arbitrary Erlang term
35
36              For each format specifier included in FormatStr, there must be a
37              corresponding argument following FormatStr. An  Erlang  term  is
38              built  according  to FormatStr with values and Erlang terms sub‐
39              stituted from the corresponding arguments, and according to  the
40              individual format specifiers. For example:
41
42              erl_format("[{name,~a},{age,~i},{data,~w}]",
43                         "madonna",
44                         21,
45                         erl_format("[{adr,~s,~i}]","E-street",42));
46
47
48              This  creates an (ETERM *) structure corresponding to the Erlang
49              term [{name,madonna},{age,21},{data,[{adr,"E-street",42}]}]
50
51              The function returns an Erlang term, or NULL if  FormatStr  does
52              not describe a valid Erlang term.
53
54       int erl_match(Pattern, Term)
55
56              Types:
57
58                 ETERM *Pattern,*Term;
59
60              This  function  is  used  to perform pattern matching similar to
61              that done in Erlang. For matching rules and more  examples,  see
62              section  Pattern Matching in the Erlang Reference Manual.
63
64                * Pattern is an Erlang term, possibly containing unbound vari‐
65                  ables.
66
67                * Term is an Erlang term that we wish to  match  against  Pat‐
68                  tern.
69
70              Term  and Pattern are compared and any unbound variables in Pat‐
71              tern are bound to corresponding values in Term.
72
73              If Term and Pattern can be matched, the function returns a  non-
74              zero  value  and binds any unbound variables in Pattern. If Term
75              and Pattern do not match, 0 is returned. For example:
76
77              ETERM *term, *pattern, *pattern2;
78              term1    = erl_format("{14,21}");
79              term2    = erl_format("{19,19}");
80              pattern1 = erl_format("{A,B}");
81              pattern2 = erl_format("{F,F}");
82              if (erl_match(pattern1, term1)) {
83                /* match succeeds:
84                 * A gets bound to 14,
85                 * B gets bound to 21
86                 */
87                ...
88              }
89              if (erl_match(pattern2, term1)) {
90                /* match fails because F cannot be
91                 * bound to two separate values, 14 and 21
92                 */
93                ...
94              }
95              if (erl_match(pattern2, term2)) {
96                /* match succeeds and F gets bound to 19 */
97                ...
98              }
99
100
101              erl_var_content() can be used to retrieve  the  content  of  any
102              variables bound as a result of a call to erl_match().
103
104
105
106Ericsson AB                  erl_interface 3.11.3                erl_format(3)
Impressum