erl_interface and lists

Serge Aleynikov serge@REDACTED
Tue May 27 05:28:48 CEST 2003


Could someone shed some light on how to decode lists' elements (other 
than head and tail) in erl_interface.  The examples included in the docs 
are pretty clear on how to decode tuples and atoms, but I can't seem to 
find any reference for functions dealing with retrieval of an N'th 
element of a list.

Suppose the Erlang side of the interface is passing a tuple to a C port:
{init, [a, b, c]}

ETERM *tuple = erl_decode(buf);
ETERM *atom  = erl_element(1, tuple);
ETERM *list  = erl_element(2, tuple);

Then what I'd like to do is to iterate over each element of the list:

for (int i=0; i < erl_length(list); i++) {
   do_smthng_with_item(ERL_NTH_ELEMENT(i, list));
}

So, how can I implement ERL_NTH_ELEMENT()?

Thanks.

Serge




More information about the erlang-questions mailing list