title: How to compare two structures via pointer equality in Elixir / Erlang
body: <p>(Example given in Elixir.)</p>
  
  <p>Suppose I have the following code,</p>
  
  <pre><code>x = {1, 2}
  a1 = {"a", {1, 2}}
  a2 = {"a", {1, 2}}
  a3 = {"a", x}
  </code></pre>
  
  <p>which as far as I know creates three tuples <code>{1, 2}</code> at different memory locations.</p>
  
  <p>Using the operators <code>==</code> or <code>===</code> for comparing any of the <code>a</code> variables always returns <code>true</code>. This is expectable, as these two operators only differ when comparing numeric types (i.e., <code>1 == 1.0</code> is different to <code>1 === 1.0</code>).</p>
  
  <p>So, I then tried comparing the structures via pattern matching, using the following  module (strictly created to test my case),</p>
  
  <pre><code>defmodule Test do
    def same?({x, y}, {x, y}), do: true
    def same?(_, _), do: false
  end
  </code></pre>
  
  <p>but calling <code>Test.same?(a1, a3)</code> also returns <code>true</code>.</p>
  
  <p>How can I compare two structures using pointer equality, so that I can determine if they are the same structure in memory?</p>
  
  <p>Thanks</p>