[erlang-questions] Irregular list

Zvi exta7@REDACTED
Thu Feb 12 17:57:13 CET 2009


too bad there is no single pattern to test for list, instead of [] and [_|_]
.

To test for proper list:

is_proper_list([_|T]) -> is_proper_list(T);
is_proper_list([]) -> true;
is_proper_list(_) -> false.

or from shell:

5> F = fun([_|T],F) -> F(T,F); ([],_) -> true; (_,_) -> false end.
#Fun<erl_eval.12.113037538>
6> 
7> F([a|b],F).
false
8> F([a,b],F).
true
9> F([],F).   
true
10> F([a,b|c],F).
false
11> F([a,b|[]],F).
true

Zvi
-- 
View this message in context: http://www.nabble.com/Irregular-list-tp21977982p21980109.html
Sent from the Erlang Questions mailing list archive at Nabble.com.




More information about the erlang-questions mailing list