I came accross this code on the web:
is_char(Ch) ->
if Ch < 0 -> false;
Ch > 255 -> false;
true -> true
end.
is_string(Str) ->
case is_list(Str) of
false -> false;
true -> lists:all(is_char, Str)
end.
Its is the Guard I alwais dreamed off, in that it checks if an input is a string -- how ever, I'm not allowed to use it in erlang, why is this? And is there a work around?
I would like to be able to write stuff like:
Fun(Str) when is_string(Str) -> Str;
Fun(Int) when is_integer(Int) -> io:format("~w", [Int]).
or even better use it on messages.