[erlang-questions] List Question

zxq9 <>
Mon Aug 7 14:24:37 CEST 2017


On 2017年08月07日 月曜日 22:13:23 Andrew McIntyre wrote:
> 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"]

Using a match this is pretty straight forward.


choose_your_adventure("FT") ->
    path_one();
choose_your_adventure(["FT" | Rest]) ->
    ok = path_two(),
    choose_your_adventure(Rest).

Generally speaking, if your system is the one generating the lists/strings then it is useful to produce them in a way that is more semantically unambiguous.

-Craig


More information about the erlang-questions mailing list