Executing boolean expressions on a list
    Shawn Pearce 
    spearce@REDACTED
       
    Fri Mar 14 03:39:13 CET 2003
    
    
  
>From lists.erl:
   625  all(Pred, [Hd|Tail]) ->
   626      case Pred(Hd) of
   627      true -> all(Pred, Tail);
   628      false -> false
   629      end;
   630  all(_, []) -> true.
It would seem that the Erlang masters implemented it exactly
as I have.  At these few points in my code, I'd rather not
do the remote function call + fun call, but lists:all/2 does
what I want.  :-)
Maybe I'll change my code.  Thanks Peter.
Peter H|gfeldt <peter@REDACTED> wrote:
> 
> How about lists:all/2, 
> 
> 	recursive(N, Es) ->
> 	    lists:all(fun(E) -> somef(N, E) end, Es)  ?
>
> /Peter
> 
> On Thu, 13 Mar 2003, Shawn Pearce wrote:
> 
> > I find I'm writing a lot of:
> > 
> > 	recursive(N, [H | T]) ->
> > 		case somef(N, H) of
> > 			true ->	recursive(N, T);
> > 			false -> false
> > 		end;
> > 	recursive(N, []) ->
> > 		true.
> > 
> > 	somef(N, E) ->
> > 		.... % return true or false.
-- 
Shawn.
  The human race is a race of cowards; and I am not only marching in that
  procession but carrying a banner.
  		-- Mark Twain
    
    
More information about the erlang-questions
mailing list