[erlang-questions] c-node and arbitrary erlang term

Scott Lystig Fritchie fritchie@REDACTED
Wed Aug 5 01:19:30 CEST 2009


Roberto Ostinelli <roberto@REDACTED> wrote:

ro> char *e_headers = "[{one, 1}, {two, 2}]";
ro> erlterm = erl_format("~w", e_headers);

I agree with Per, that won't work.  However, this should, if memory
serves correctly.

    ETERM *erlterm = erl_format("[{one, 1}, {two, 2}]");

erl_format() won't  work well with  C programs with limited  stack sizes
(e.g. when using Pthreads).  It uses naive recursion for formatting
nested terms, which can cause problems for deeply-nested and/or
extremely long lists.  In those cases, you can usually get by with a
small number of intermediate steps.

    ETERM *very_long_list = format_myself_by_hand(a_long_linked_list);
    ETERM *my_tuple = erl_format("{ok, ~w}", very_long_list);

IIRC, erl_format() doesn't have a format command for dealing with
binaries.  But the ~w format command will work on a previously-created
binary, e.g. ETERM *my_bin = erl_mk_binary("Hello!", 6).

-Scott


More information about the erlang-questions mailing list