[erlang-questions] jinterface List vs. String

Vlad Dumitrescu vladdu55@REDACTED
Tue Dec 9 11:15:46 CET 2008


On Tue, Dec 9, 2008 at 10:54, Robert Raschke <rtrlists@REDACTED> wrote:
> does anyone have a good idea on how I can distinguish between a list
> and a string in jinterface?

The short answer is that you can't without traversing the list/string.
Since there is no string datatype in Erlang, the two are only
differentiated by their contents.

> Or, in other words, if jinterface has decided to receive an
> OtpErlangString (from a sent list like [1, 2, 3], for example), is
> there an easy way to convert it to an OtpErlangList? I know I can do
> it by hand, but that's ever so slightly icky.

Actually, it is Erlang that decides to encode a list as a STRING_EXTor
as a LIST_EXT, as an optimization.

The way to handle that is by expecting either a list or a string and
convert from each of them to the Java class you're going to use.
Slightly icky, as you say...

Maybe OtpErlangString should have inherited from OtpErlangList?

best regards,

More information about the erlang-questions mailing list