[erlang-questions] Finding records in List

Robert Virding <>
Thu Jan 13 22:21:46 CET 2011


----- "David Mercer" <> wrote:

> 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.)

Hopefully records in matches are not out of favour, it is the most erlangy way of doing it. Otherwise it would be like using element/2 instead of matching tuples. Exactly like actually.

The match version is probably more efficient.

Robert

-- 
Robert Virding, Erlang Solutions Ltd.



More information about the erlang-questions mailing list