19962013 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 961016 A erl_format.sgml
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, ... ) Creates an Erlang term 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 works.

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 , there must be a corresponding argument following . An Erlang term is built according to the with values and Erlang terms substituted from the corresponding arguments and according to the individual format specifiers. For example:

This will create 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) Performs pattern matching 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.

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 do not match, the function returns 0. For example:

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