19962016 Ericsson AB. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. erl_format Torbjörn Törnkvist Torbjörn Törnkvist Bjarne Däcker Torbjörn Törnkvist 1996-10-16 A erl_format.xml
erl_format Create and match Erlang terms.

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

ETERM *erl_format(FormatStr, ...) Create an Erlang term. char *FormatStr;

A general function for creating Erlang terms using a format specifier and a corresponding set of arguments, much in the way works.

is a format specification string. The valid format specifiers are as follows:

~i - Integer ~f - Floating point ~a - Atom ~s - String ~w - Arbitrary Erlang term

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

This creates an structure corresponding to the Erlang term

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

interl_match(Pattern, Term) Perform pattern matching. ETERM *Pattern,*Term;

This function is used to perform pattern matching similar to that done in Erlang. For matching rules and more examples, see section Pattern Matching in the Erlang Reference Manual.

is an Erlang term, possibly containing unbound variables. is an Erlang term that we wish to match against .

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

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

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