try catch scope

Magnus Henoch <>
Wed Jun 30 13:53:30 CEST 2010

Wes James <> writes:

> has_query(A) ->
> 		case length(yaws_api:parse_query(A)) of
> 			0  -> false;
> 			_ -> true
> 		end.

A separate note about the code: you should avoid "case length(Foo)" when
possible, since length/1 needs to traverse the entire list.  Just
comparing the result to the empty list is probably faster:

case yaws_api:parse_query(A) of
    [] -> false;
    _ -> true

And this can be simplified further:

yaws_api:parse_query(A) /= [].

(There is a difference between my two examples and yours: your code will
crash with badarg if the result is not a proper list, while mine will
just return false.)

Magnus Henoch, 
Erlang Solutions

More information about the erlang-questions mailing list