[erlang-questions] Basic questions, also related to yaws and mnesia

Fredrik Thulin ft@REDACTED
Tue Oct 16 10:02:28 CEST 2007


Berlin Brown wrote:
> I should probably move away from yaws for a sec and go over the
> basics, but I am really close to what I want to do.
> 
> I have a record and a list of records, but I don't know the best ways
> to extract the data and show the data out of the record.
> 
> For example, with this code; how would I iterate(map?) those links and
> display them.
> 
> out(Args) ->
> 	{ok, EntityLinks} = botlist_find_links:find_links(),
> 	{ html,
> 	 	yaws_api:f("~p", [EntityLinks])
> 	}.
> 
> This is the record.
> -record(entity_links, {main_url, url_title, keywords, rating,
> full_name, created_on}).
> 

If I understand correctly what you want to do, try something like this :

out(Args) ->
     {ok, EntityLinks} = botlist_find_links:find_links(),
     {html, [
         [pretty_print(Entity) || Entity <- EntityLinks]
     ]}.

pretty_print(Entity) ->
     {p, [], [Entity#entity_links.main_url]}.

Totally untested. This will call pretty_print/1 once for each entry in 
the EntityLinks list, so that you can extract whatever information you 
want from each of the entity_link records.

/Fredrik



More information about the erlang-questions mailing list