<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="232854" data-post-id="232854">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="trisolaran" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/trisolaran/120/23748_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  trisolaran
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks <a class="mention" href="/u/lostkobrakai" rel="nofollow">@LostKobrakai</a> that’s the best answer I’ve seen to this question so far.</p>
<p>So the reason why this works:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex(2)&gt; one = 1
1
iex(3)&gt; %{a: ^one} = %{a: 1, b: 2}
%{a: 1, b: 2}
</code></pre>
<p>But this one doesn’t:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex(1)&gt; map_with_one = %{a: 1}
%{a: 1}
iex(2)&gt; ^map_with_one = %{a: 1, b: 2}
** (MatchError) no match of right hand side value: %{a: 1, b: 2}
</code></pre>
<p>Is because the pin operator can only be used for exact matches but not for partial ones, the reason being intrinsic limitations of the BEAM. Correct?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="232854" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pattern-matching-with-variables-and-the-pin-operator/44013/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-232854" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="232854"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="232857" data-post-id="232857">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes, but I’d suggest not even trying to think of it like that. There’s (runtime) data assigned to a variable like <code>map_with_one</code> and there’s syntax, which can in some cases look exactly like the syntax used to define the data for <code>map_with_one</code>, but which forms a pattern for a pattern match. One is completely unrelated to the other. This becomes even more apparent when you consider the features of a match pattern, which a map of data doesn’t support, like <code>_</code> for ignoring values or variable assignments <code>%{a: a} = …</code>.</p>
<p>The pin operator is a way to use data assigned to a variable to be equality matched within a pattern. Nothing more and nothing less. It does not become <em>a</em> pattern by itself. Patterns are compile time structures, which cannot be adjusted at runtime, stored in a variable or otherwise modified after compilation is done. Only patterns can be used for a pattern match on the left side of the match operator (<code>=</code>). When you put a variable on the left side it’s either an assignment, or if you use a pin an equality check to match the pattern.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="232857" data-batch-url="/posts/batch_likers">
                        11
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pattern-matching-with-variables-and-the-pin-operator/44013/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-232857" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="232857"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="232858" data-post-id="232858">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="trisolaran" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/trisolaran/120/23748_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  trisolaran
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks! Excellent explanation <img src="https://forum.elixirforum.com/images/emoji/apple/+1.png?v=15" title=":+1:" class="emoji" alt=":+1:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="232858" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/pattern-matching-with-variables-and-the-pin-operator/44013/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-232858" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="232858"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>