title: Understanding what this Erlang Code is?
body: <p>Not at all familiar with Erlang, but am trying to interpret what this code does?</p>
  
  <p>Below is my understanding about the code. Any help will be useful.
  I am looking at the tutorials but the passing values are confusing in this case.</p>
  
  <p>example- <code>convert_list_to_k([{Name, {l, Weight}} | Rest]) //{1,Weight} &lt;- This one</code></p>
  
  <p>And how is the value returned in <code>convert_list_to_k</code>?</p>
  
  <p>let's say for this function block</p>
  
  <pre><code>convert_list_to_k([{Name, {l, Weight}} | Rest]) -&gt;
      Converted_Object = {Name, {k, Weight / 0.45359237}},
      [Converted_Object | convert_list_to_k(Rest)];
  
  convert_list_to_k([Object | Rest]) -&gt;
      [Object | convert_list_to_k(Rest)];
  
  convert_list_to_k([]) -&gt;
      [].
  </code></pre>
  
  <hr>
  
  <h2>Below is the code with explanations.</h2>
  
  <pre><code>-module(erlang_program).
  -export([format_weight/1]).
  </code></pre>
  
  <p>in the above export the /1 represents it's going to receive an attribute(I don't know which attribute)</p>
  
  <pre><code>format_weight(List_of_objects) -&gt;
      Converted_List = convert_list_to_k(List_of_objects),
      print_weight(Converted_List),
      {Max_object, Min_object} = find_max_and_min(Converted_List),
      print_max_and_min(Max_object, Min_object).
  </code></pre>
  
  <p>Kind of main function, which will import <code>convert_list_to_k</code>, <code>print_weight(Converted_List)</code>,<code>find_max_and_min(Converted_List)</code> and <code>print_max_and_min(Max_object, Min_object).</code></p>
  
  <p>According to my understanding it's doing the following things:</p>
  
  <ol>
  <li>Converts a list of object to some format</li>
  <li>Prints the converted list</li>
  <li>Find the Max and Min, and place it in Object Max and Min</li>
  <li>Prints the Max and Min Object</li>
  </ol>
  
  <hr>
  
  <p>I am getting confused by the way <code>[{Name, {l, Weight}} | Rest]</code> is passed</p>
  
  <pre><code>convert_list_to_k([{Name, {l, Weight}} | Rest]) -&gt;
      Converted_Object = {Name, {k, Weight / 0.45359237}},
      [Converted_Object | convert_list_to_k(Rest)];
  
  convert_list_to_k([Object | Rest]) -&gt;
      [Object | convert_list_to_k(Rest)];
  
  convert_list_to_k([]) -&gt;
      [].
  </code></pre>
  
  <hr>
  
  <pre><code>print_weight([{Name, {k, Weight}} | Rest]) -&gt;
      io:format("~-15w ~w c~n", [Name, Weight]),
      print_weight(Rest);
  
  print_weight([]) -&gt;
      ok.
  
  find_max_and_min([Object | Rest]) -&gt;
      find_max_and_min(Rest, Object, Object).
  
  find_max_and_min([{Name, {k, Weight}} | Rest], 
           {Max_Name, {k, Max_Weight}}, 
           {Min_Name, {k, Min_Weight}}) -&gt;
      if 
          Weight &gt; Max_Weight -&gt;
              Max_Object = {Name, {k, Weight}};
          true -&gt; 
              Max_Object = {Max_Name, {k, Max_Weight}}
      end,
      if
           Weight &lt; Min_Weight -&gt;
              Min_Object = {Name, {k, Weight}};
          true -&gt; 
              Min_Object = {Min_Name, {k, Min_Weight}}
      end,
      find_max_and_min(Rest, Max_Object, Min_Object);
  
  find_max_and_min([], Max_Object, Min_Object) -&gt;
      {Max_Object, Min_Object}.
  
  print_max_and_min({Max_name, {k, Max_object}}, {Min_name, {k, Min_object}}) -&gt;
      io:format("Max weight was ~w c in ~w~n", [Max_object, Max_name]),
      io:format("Min weight was ~w c in ~w~n", [Min_object, Min_name]).
  </code></pre>