[erlang-questions] How to Convert a Mixed Term to String

Matthias Lang matthias@REDACTED
Mon Nov 6 08:25:14 CET 2006


Jeff Crane writes:
 > When testing my app by reading a file, I could easily
 > pull a string like:
 > "{String1,{atom2,{3,4}},5,6}"
 > 
 > But when I pull from an erlang MySQL implementation, I
 > end up with:
 > {"String1",{atom2,{3,4}},5,6}
 > and I cannot figure out how to convert it to:
 > "{String1,{atom2,{3,4}},5,6}"
 > since transforms seem to always remove the curly
 > braces.
 > 
 > Can anyone describe how they would go about this?
 > 
 > It's really frustrating to be stuck on a formatting issue.

Based on the limited information you've given, in conjunction with the
level of previous questions you've asked on the mailing list, my guess
is that you are confused about what a 'term' is.

The following is a term: 
    {"String1",{atom2,{3,4}},5,6}

The following is a string. The string does _not_ represent a valid term:
    "{String1,{atom2,{3,4}},5,6}"

Since the two are _not_ alternative representations of the same thing,
at least not under the definition of "an Erlang term", Erlang isn't
going to solve it for you with some "formatting fix".

You can, of course, write your own code to convert between the two
under some set of rules which you can invent. Or, you could read up on
terms, for instance in chapter 2 of the Erlang reference manual.

It is also possible that you've mistyped the examples in your question, in
which case my answer is mostly irrelevant.

Matthias



More information about the erlang-questions mailing list