[erlang-questions] List Question

Dmytro Lytovchenko dmytro.lytovchenko@REDACTED
Mon Aug 7 14:27:04 CEST 2017

A string is a list of integers [$F, $T] (where $x is a code for the letter
x and so on)
A list of strings is a — List of lists of integers. That is [ [$F, $T],
[$S, $T] ]
So to check whether a value is a list of lists you take its first element
and check whether it's also a list

function([X | _] = List) when is_list(X) -> got a nonempty list of strings!
function([X | _]) when is_list(X) -> got a nonempty list of integers (one
function([]) -> i am sorry, empty list is here

there is no way to know having an empty list what it supposed to contain.
So an empty list is an empty list

2017-08-07 14:13 GMT+02:00 Andrew McIntyre <andrew@REDACTED>:

> 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
> www.medical-objects.com.au
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170807/a8a9600f/attachment.htm>

More information about the erlang-questions mailing list