[erlang-questions] Finding records in List

David Mercer <>
Thu Jan 13 16:17:22 CET 2011


On Thursday, January 13, 2011, Bengt Kleberg wrote:

> is_name_and_age( Person, Name, Age ) ->
> 	(Person#person.name =:= Name) andalso (Person#person.age =:= Age)

Question about style: is there any preference between what Bengt wrote, and:

	is_name_and_age(#person{name = Name, age = Age}, Name, Age) -> true;
	is_name_and_age(_,_,_) -> false.

In fact, I think I like Bengt's better, since it is more clear about intent,
but I'd have written it as the latter figuring that that was more idiomatic.
Are records in match specifications out of favor?  (To a certain extent, if
they are, good.)

Cheers,

DBM



More information about the erlang-questions mailing list