Question on functional style

Vance Shipley vances@REDACTED
Fri Sep 9 21:05:26 CEST 2005


On Fri, Sep 09, 2005 at 08:44:14PM +0200, Hkan Stenholm wrote:
}  
}  The following replacement code springs to mind:
}
}  start(Arg) ->
}     F = fun(E) -> 
}         lists:member(E, Arg) 
}     end,
}     Matches = [foo,bar,baz],
}     case lists:any(F, Matches) of
}         true -> phase2();
}         false -> ok
}     end.
  
Mine was a contrived example.  The actual code is much more 
complicated with tests being done on a combination of received
data, state data and database access.

}  start(Arg) ->
}     try begin
}         false = lists:member(foo, Arg),
}         false = lists:member(bar, Arg),
}         false = lists:member(baz, Arg)
}     end
}     catch
}         throw:error ->    % should it be 'exit' ?
}             phase2()
}     end.
...
}  This relies on Erlang generating a runtime exception if one of the 
}  lists:member/2 calls become = 'true'. My personal choice would be to 
}  write the code without any exceptions, as their use implies a unexpected 
}  execution path in the code, rather than a standard path.

The above definetly gets my guard up as it does imply an error in
an expected execution path.  This was also my concern about using 
throw.

	-Vance




More information about the erlang-questions mailing list