[erlang-questions] (Newbie) extracting value for one key

Brian Candler <>
Tue Aug 19 14:18:32 CEST 2008

In Erlang, it seems a list of {key,value} tuples is often returned, e.g.

17> P = process_info(self()).

Question: What's the idiomatic way to extract the value for a particular
key? For example, to extract "stack_size" from the above I could write

18> hd([ V || {stack_size,V} <- P ]).

but is there a better way to do this?



P.S. I found the example at
which shows how to factor the comprehension into a function.

I also found "element(2, element(2, lists:keysearch(stack_size, 1, P)))."
but that's rather verbose.

More information about the erlang-questions mailing list