Erlang is a great language to work with. I need to concentrate on the business logic rather than nifty details about the distributed computing like communication between nodes, handle node failures, restart apps etc. All these details are already taken care by the language itself. Yes.. distributed computing and concurrent programming is a integrated part of the language.

Erlang implement string in terms of list. So it is tricky to distinguish regular string from the list. For example,


foo(C) when is_string(C) ->
% do something with string;
foo(C) when is_list(C) ->
% do something with list.

First of all there is no function called “is_string” in Erlang. (I just made it up). But the point here is that how to distinguish regular string from the list. I came up with this solution.


foo(C) when lists:flatten(C) == C ->
% do something with string;
foo(C) when is_list(C) ->
% do something with list.

Somewhat inefficient because of call to lists:flatten/1 call. But for small strings, it is not an issue at all.

Advertisements