[erlang-questions] List Question

Oliver Korpilla Oliver.Korpilla@REDACTED
Mon Aug 7 14:57:28 CEST 2017


Hello.

I would have done something like this:

is_string(Input) when is_list(Input) -> lists:all(fun erlang:is_integer/1, Input);
is_string(_Input) -> false.
 
This works fine for regular strings (lists of integers).

Erlang, however, often uses a construct called iolist for performant formatting of output. And these can contain lists of strings or list of lists in arbitrary depth, also not requiring them to be proper lists (they need not end with the empty list []). There more work would be required.

Cheers,
Oliver


Gesendet: Montag, 07. August 2017 um 14:13 Uhr
Von: "Andrew McIntyre" <andrew@REDACTED>
An: "Erlang-Questions Questions" <erlang-questions@REDACTED>
Betreff: [erlang-questions] List Question
Hello All,

A Newbie question,

Can I tell the difference Between a List of Strings and a Single
String?

eg the Value in a List may just be "FT" or it might be ["FT", "ST"]

I do not know in advance if its a single string or a list of strings,
but want to behave differently - actually return the first element of
the list when there are multiple values. I have parsed a variable
hierarchical structure and the hierarchy can vary over instances.

As strings are lists "is_list" returns true for both. Is that soluble
or do I need to change the data structure to indicate it. Sorry if
this has obvious answer, but new to erlang.

Thanks

--
Best regards,
Andrew McIntyre mailto:andrew@REDACTED

sent from a real computer

R&D Director
Medical-Objects
4/102 Wises Road
MAROOCHYDORE Q 4558
AUSTRALIA

www.medical-objects.com.au[http://www.medical-objects.com.au]


_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions[http://erlang.org/mailman/listinfo/erlang-questions]



More information about the erlang-questions mailing list