title: Elixir case statement and pattern matching
body: <p>I am trying to paint a room with walls into a map of <code>%{{x, y} =&gt; [items]}</code> and I am using a case statement to figure out what type of wall I want to draw.</p>
  
  <p>However it sems to try to do pattern matching and assign <code>pos</code> to the values on left. (throwing <code>illegal pattern</code> compilation error)</p>
  
  <p>I know I can prevent assignment with <code>^</code>, but what about the cases where I need to do <code>(from_y+sizey)</code>?</p>
  
  <pre><code>def place_room({from_x, from_y}, {size_x, size_y}, original_map) do
    Enum.reduce from_x..(from_x + size_x-1), original_map, fn x, map -&gt;
      Enum.reduce from_y..(from_y + size_y-1), map, fn y, map -&gt;
        pos = {x, y}
        case pos do
          {from_x, from_y} -&gt;
            place(map, pos, :wall, %{type: :room_wall_tl})
          {from_x, (from_y+size_y)} -&gt;
            place(map, pos, :wall, %{type: :room_wall_tr})
          {from_x, (from_y+size_y)} -&gt;
            place(map, pos, :wall, %{type: :room_wall_bl})
          {(from_x+size_x), (from_y+size_y)} -&gt;
            place(map, pos, :wall, %{type: :room_wall_br})
          {_, _} -&gt;
            place(map, pos, :floor, %{type: :room_floor})
          weird -&gt;
              IO.inspect weird
        end
      end
    end
  end
  </code></pre>
  
  <p>How would you write this?</p>