<div dir="ltr"><a href="http://www.erlang.org/doc/man/proplists.html">http://www.erlang.org/doc/man/proplists.html</a><br><br>proplists:get_value(stack_size,P).<br><br><div class="gmail_quote">On Tue, Aug 19, 2008 at 2:18 PM, Brian Candler <span dir="ltr"><<a href="mailto:B.Candler@pobox.com">B.Candler@pobox.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">In Erlang, it seems a list of {key,value} tuples is often returned, e.g.<br>
<br>
17> P = process_info(self()).<br>
[{current_function,{erl_eval,do_apply,5}},<br>
 {initial_call,{erlang,apply,2}},<br>
 {status,running},<br>
 {message_queue_len,0},<br>
 {messages,[]},<br>
 {links,[<0.25.0>]},<br>
 {dictionary,[]},<br>
 {trap_exit,false},<br>
 {error_handler,error_handler},<br>
 {priority,normal},<br>
 {group_leader,<0.24.0>},<br>
 {heap_size,610},<br>
 {stack_size,28},<br>
 {reductions,526},<br>
 {garbage_collection,[{fullsweep_after,65535}]}]<br>
<br>
Question: What's the idiomatic way to extract the value for a particular<br>
key? For example, to extract "stack_size" from the above I could write<br>
<br>
18> hd([ V || {stack_size,V} <- P ]).<br>
28<br>
<br>
but is there a better way to do this?<br>
<br>
Thanks,<br>
<br>
Brian.<br>
<br>
P.S. I found the example at<br>
<a href="http://www.erlang.org/doc/programming_examples/list_comprehensions.html#3.6" target="_blank">http://www.erlang.org/doc/programming_examples/list_comprehensions.html#3.6</a><br>
which shows how to factor the comprehension into a function.<br>
<br>
I also found "element(2, element(2, lists:keysearch(stack_size, 1, P)))."<br>
but that's rather verbose.<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>