title: Erlang foreach gives error: syntax error before: ')'
body: <p>Im doing a parallell sodukusolver but right now the program gives me an error. Im trying to spawn processes in parallel that test different possible solutions. Part of the code is below.</p>
  
  <pre><code>par_solve_refined(M) -&gt;
    case solved(M) of
      true -&gt;
        M;
      false -&gt;
        %% split into chunks to control granularity
        Chunks = partition(2, guesses(M)),
        Parent = self(),
        %% here below the program gives an error: "syntax error before: ')'"
        foreach(fun(I) -&gt; spawn(fun() -&gt; Parent ! solve_one(I) end) end, Chunks),
        receive
          Solution -&gt; Solution
        end
    end.        
  
  partition(_, []) -&gt;
     [];
  partition(N, L) -&gt;
     try case lists:split(N, L) of
          {Fst, Snd} -&gt; [Fst|partition(N, Snd)]
         end
     catch
       error:badarg -&gt; [L]
  end.
  </code></pre>