Lists of records

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Lists of records

Hi All,

I'm new to Erlang, and I'm still trying to get familiar with lists and

I have a (small) list containing records (all of the same type) and I'm
trying to write a function to return a record when supplied with a field
name and value.
I'm happy to assume the field name chosen happens to contain unique values
for now.

I've tried a few things, including the idea below.. but I'm not having much
Is there a way to do something like this without hardcoding the Fieldname?

Are there any other docs and/or examples on the subject of records apart
from the "Erlang Extensions Since 4.4" doc?

find_record(Fieldname,Searchvalue,[H|T]) ->
    case H of
        #recordtype1{Fieldname=Searchvalue} ->
        _ ->
find_record(Fieldname,Searchvalue,[]) ->

The above seems to compile & work only if Fieldname is replaced with an

I had also hoped to extend this so that the recordtype isn't hardcoded.. any

Thanks & Regards,
Julian Noble