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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Since everything is immutable and also there is nothing shared between 2 BEAM processes[1], there is no issue with that code in terms of concurrent processing.</p>
<p>[1] Well, in fact, large binaries are shared across processes, but as they are still immutable we do not get any problems because of this as well.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="32657" data-batch-url="/posts/batch_likers">
                        3
                      </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/whats-the-difference-between-variable-binding-and-assignment/4971/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-32657" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32657"
                     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="32723" data-post-id="32723">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="nezzart" data-post="10" data-topic="4971">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/n/e36b37/48.png" class="avatar"> nezzart:</div>
<blockquote>
<p>moreover, how’s that diffrent from?</p>
<pre><code>def my_fun do
   # ...
  get_new_value(123, :something)
  |&gt; get_new_value(:something2)
end
</code></pre>
</blockquote>
</aside>
<p>That code ignores two guidelines:</p>
<ul>
<li><a href="https://github.com/christopheradams/elixir_style_guide#avoid-single-pipelines" rel="noopener nofollow ugc">Avoid using the pipe operator just once.</a></li>
<li><a href="https://github.com/christopheradams/elixir_style_guide#bare-variables" rel="noopener nofollow ugc">Use bare variables in the first part of a function chain.</a></li>
</ul>
<aside class="quote no-group" data-username="nezzart" data-post="11" data-topic="4971" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/n/e36b37/48.png" class="avatar"> nezzart:</div>
<blockquote>
<p>my question was about multithreading safety and related stuff.</p>
</blockquote>
</aside>
<p>I’m not sure how anybody could be expected to “divine” this given that this was the first mention of it <strong>and</strong> since Erlang/Elixir’s BEAM implements a share-nothing architecture (as <a class="mention" href="/u/nobbz" rel="nofollow">@NobbZ</a> already mentioned).</p>
<ul>
<li>The BEAM runs inside an OS process</li>
<li>The BEAM starts a scheduler (i.e. with an OS thread) for each physical core available</li>
<li>The schedulers pre-emptively schedule BEAM processes on their respective cores.</li>
</ul>
<p>i.e. there is no concept of “multi-threading” in Erlang/Elixir. If BEAM processes need to coordinate their activities they need to go through the BEAM process mailboxes.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="32723" data-batch-url="/posts/batch_likers">
                        1
                      </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/whats-the-difference-between-variable-binding-and-assignment/4971/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-32723" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32723"
                     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="32755" data-post-id="32755">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The difference is more obvious in a language that has both.</p>
<ul>
<li>
<p>Bindings introduce new variables, while assignments use existing ones.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">my_var = 3 # bind my_var to 3
assert my_var == 3
</code></pre>
<pre data-code-wrap="javascript"><code class="lang-javascript"># Assuming a version of Elixir with an assignment operator called `set`
#set my_var = 3 # COMPILATION FAIL
</code></pre>
</li>
<li>
<p>Bindings are subject to their own lexical scope, while assignment makes the new value accessible through the scope that the initial binding was in.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">my_var = 3
if true do
    my_var = 4
end
assert my_var == 3
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">my_var = 3
if true do
    set my_var = 4
end
assert my_var == 4
</code></pre>
</li>
<li>
<p>Bindings can use any (irrefutable) pattern, while assignments require an lvalue.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{var1, var2} = {1, "super"}
assert var1 == 1
assert var2 == "super"
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">{var1, var2} = {1, "super"}
#set {var1, var2} = {2, "duper"}; # COMPILATION FAIL
</code></pre>
</li>
<li>
<p>Variable bindings may be of different types, even if they have the same name. In languages with a static type system, assignment cannot change a variable’s type:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">x = 1
x = "awesome!"
assert x == "awesome!"
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">x = 1
#set x = "awesome!" # COMPILATION FAIL
</code></pre>
</li>
</ul> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="32755" data-batch-url="/posts/batch_likers">
                        1
                      </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/whats-the-difference-between-variable-binding-and-assignment/4971/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-32755" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32755"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="32790" data-post-id="32790">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>That’s a good way to think of it, like OCaml has 3 syntax’s for this:</p>
<pre data-code-wrap="ocaml"><code class="lang-ocaml">(* This creates a new immutable binding *)
let a = 42
(* `a` cannot be changed, only re-bound like how Elixir does it *)

(* This creates a new mutable binding *)
let b = ref 42
(* It can be changed within its scope *)
let () = b := 21
(* The `:=` operator means `to change where the binding points to` in a sense,
    It returns empty tuple, so you can pattern match that as above, or ignore it.
    It is indeed made purposefully cumbersome to minimize its use. *)
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="32790" data-batch-url="/posts/batch_likers">
                        1
                      </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/whats-the-difference-between-variable-binding-and-assignment/4971/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-32790" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32790"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="32907" data-post-id="32907">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="nezzart" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  nezzart
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="peerreynders" data-post="13" data-topic="4971">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/48/5826_2.png" class="avatar"> peerreynders:</div>
<blockquote>
<p>That code ignores two guidelines:</p>
<p>Avoid using the pipe operator just once.<br>
Use bare variables in the first part of a function chain.</p>
</blockquote>
</aside>
<p><code>    get_new_value(get_new_value(123, :something), :something2)</code></p>
<p>that’s it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="32907" 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/whats-the-difference-between-variable-binding-and-assignment/4971/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-32907" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32907"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="32909" data-post-id="32909">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Qqwy" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Qqwy/120/1349_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Qqwy
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>TypeCheck Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Maybe this is an intuitive way to think about the difference:</p>
<ul>
<li>with assignment, you copy/move the value while the name (the memory location the name points to) stay the same.</li>
<li>with binding, you move the name (the memory location the name points to) while the value stays the same.</li>
</ul>
<p><img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji only-emoji" alt=":slight_smile:" 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="32909" 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/whats-the-difference-between-variable-binding-and-assignment/4971/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-32909" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32909"
                     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>