[erlang-questions] How to make a short circuit in erlang ?

Richard A. O'Keefe ok@REDACTED
Tue Mar 26 22:37:36 CET 2013


On 27/03/2013, at 5:18 AM, J K wrote:

> Hi,
> maybe this would work?
> http://en.wikipedia.org/wiki/Higher-order_function
> 
> or_else([], _) -> false;
> or_else([F | Fs], X) -> or_else(Fs, X, F(X)).
> 
> or_else(Fs, X, false) -> or_else(Fs, X);
> or_else(Fs, _, {false, Y}) -> or_else(Fs, Y);
> or_else(_, _, R) -> R.
> 
>  
> 
> or_else([fun erlang:is_integer/1, fun erlang:is_atom/1, fun erlang:is_list/1],3.23).

But we can already write

	X = 3.23,
	( is_integer(X) orelse
	  is_atom(X)    orelse
	  is_list(X)
	)

so what would be the point?

From the OP's point of view, this is surely still nesting.




More information about the erlang-questions mailing list