<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="236993" data-post-id="236993">
  <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>I wrote up most of a post about the potential to just have <code>:map_reduce</code> besides the existing <code>:reduce</code> to handle the fact that the existing implementation doesn’t handle map reduce operations well. To me this seems like the most straight forward step.</p>
<p>However I discared it because I don’t think that captures all the concerns of this proposal. One part is the lack of map reduce, but I guess the other important part is figuring out a declarative syntax for reduction operations. The things I currently don’t feel work great in the proposal in regards to the latter concern is two fold.</p>
<ul>
<li>One is that we assign initial values with <code>=</code>. <code>for let count = 0, …</code> still looks a lot like <code>count</code> would just be <code>0</code>. Yes there’s a <code>let</code> in front, but to me that doesn’t feel like proper signaling. Added parenthesis add a bit more “look at me”, but also look more like a independant function/macro than a part of <code>for</code>. (Also the fact that we use text/a name seems to be reason for a lot of the current discussion, can we possibly not use a word?) It seems all existing places where variables are assigned, but have different semantics than <code>=</code> elixir uses <code>&lt;-</code> or <code>-&gt;</code> in some shape or form. <code>&lt;-</code> just is already used to denote generators in <code>for</code>. Maybe <code>-&gt;</code> works?</li>
</ul>
<pre data-code-wrap="elixir"><code class="lang-elixir">for {0, 0} -&gt; {sum, count}, i &lt;- [1, 2, 3] do
 …
end
</code></pre>
<p>To me assigning an initial value actually reminds me a lot of assigning a default. Something like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for {sum, count} \\ {0, 0}, i &lt;- [1, 2, 3] do
 …
end
</code></pre>
<ul>
<li>The other part is the fact that while the “input” side to the <code>do/end</code> block is now more declarative we still retain the not so pretty fact of returning tuples of values because we need multiple returns for a map_reduce. It works, but doesn’t feel great. Though I’m also not sure there’s good alternatives with the current syntax elixir can parse without limiting when/how the accumulator can be manipulated.</li>
</ul>
<p>I hardly did digging into the already discarded proposals, so I hope I didn’t reiterate.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="236993" 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/introducing-for-let-and-for-reduce/44773/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-236993" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="236993"
                     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 #22"></div>
  </section>
</div>
    <div class="postbit" id="236998" data-post-id="236998">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                    <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 class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="23" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<p>Yes there’s a <code>let</code> in front, but to me that doesn’t feel like proper signaling. Added parenthesis add a bit more “look at me”, but also look more like a independant function/macro than a part of <code>for</code>. (Also the fact that we use text/a name seems to be reason for a lot of the current discussion, can we possibly not use a word?)</p>
</blockquote>
</aside>
<p>I think this explains exactly why adding the parenthesis is growing on me. At the same time, I think not using a word will make it worse, because the lack of name won’t make what it does obvious and there will be no way to distinguish between <code>let</code> and <code>reduce</code>. At the same time, I am not worried about people thinking they could use <code>let</code> or <code>reduce</code> elsewhere, we can have good error message for such cases.</p>
<p>Regarding using other operators, I think <code>\\</code> is not a good choice because what happens in this case:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">sum = ...

for let(sum \\ 0), ...
</code></pre>
<p>One would argue that <code>sum</code> should not be reset to 0 (and therefore <code>\\</code> has no use in the example above).</p>
<p>We could use <code>for let({sum, count} &lt;- {0, 0})</code> but I think making it look like a generator will be confusing. <code>let({0, 0} -&gt; {sum, count})</code> is not good either as the semantics of <code>-&gt;</code> usually is: “match on those variables on the left side and then execute the right side”. It doesn’t really assign left to right. <img src="https://forum.elixirforum.com/images/emoji/apple/frowning.png?v=15" title=":frowning:" class="emoji" alt=":frowning:" 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="236998" data-batch-url="/posts/batch_likers">
                        2
                      </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/introducing-for-let-and-for-reduce/44773/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-236998" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="236998"
                     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 #23"></div>
  </section>
</div>
    <div class="postbit" id="236999" data-post-id="236999">
  <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">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="24" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Regarding using other operators, I think <code>\\</code> is not a good choice because what happens in this case:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">sum = ...

for let(sum \\ 0), ...
</code></pre>
<p>One would argue that <code>sum</code> should not be reset to 0 (and therefore <code>\\</code> has no use in the example above).</p>
</blockquote>
</aside>
<p>To me implicitly using the values of variables declared outside the <code>for</code> for accumulator variables would be more confusing than helping. If someone wants to use the existing <code>sum</code> I’d expect them to write <code>sum \\ sum</code>, while <code>sum \\ 0</code> in your example starts from <code>0</code>. This would align with how <code>for sum &lt;- sum, do: …</code> acts.</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="24" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>We could use <code>for let({sum, count} &lt;- {0, 0})</code> but I think making it look like a generator will be confusing. <code>let({0, 0} -&gt; {sum, count})</code> is not good either as the semantics of <code>-&gt;</code> usually is: “match on those variables on the left side and then execute the right side”. It doesn’t really assign left to right.</p>
</blockquote>
</aside>
<p>Yeah, I expected that response (hence the trailing ?). I can see the reasoning, but also given <code>&lt;-</code> does work differently between <code>with</code> and <code>for</code> I don’t feel as strongly if <code>for</code> would have it’s own meaning for <code>-&gt;</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="236999" 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/introducing-for-let-and-for-reduce/44773/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-236999" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="236999"
                     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 #24"></div>
  </section>
</div>
    <div class="postbit" id="237001" data-post-id="237001">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="24" data-topic="44773" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>I think this explains exactly why adding the parenthesis is growing on me.</p>
</blockquote>
</aside>
<p><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"> Same here.</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="24" data-topic="44773" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>At the same time, I am not worried about people thinking they could use <code>let</code> or <code>reduce</code> elsewhere, we can have good error message for such cases.</p>
</blockquote>
</aside>
<p>To an extent this code:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for let sum = 0, i &lt;- [1, 2, 3], do: ...
</code></pre>
<p>suggests that I can possibly do:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">let sum = 0
</code></pre>
<p>elsewhere because defining a variable is quite similar:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">sum = 0
</code></pre>
<p>On the other hand:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for let(sum = 0), i &lt;- [1, 2, 3], do: ...
</code></pre>
<p>would mean that I need to use</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">let(sum = 0)
</code></pre>
<p>in my code, which personally gives me a feeling that it won’t work elsewhere. I admit that it’s not a very strong argument though.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237001" 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/introducing-for-let-and-for-reduce/44773/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-237001" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237001"
                     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 #25"></div>
  </section>
</div>
    <div class="postbit" id="237004" data-post-id="237004">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                    <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 class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="25" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<p>If someone wants to use the existing <code>sum</code> I’d expect them to write <code>sum \\ sum</code>, while <code>sum \\ 0</code> in your example starts from <code>0</code>. This would align with how <code>for sum &lt;- sum, do: …</code> acts.</p>
</blockquote>
</aside>
<p>It aligns with <code>for sum &lt;- sum</code> but it is completely misaligned with how <code>sum \\ sum</code> works, as that would never be possible in its usage today. Having a default is conceptually too different from setting an initial value.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237004" 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/introducing-for-let-and-for-reduce/44773/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-237004" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237004"
                     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 #26"></div>
  </section>
</div>
    <div class="postbit" id="237005" data-post-id="237005">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                    <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 class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh, this discussion gave me another idea for a name, <code>init</code>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for init(sum = 0), x &lt;- [1, 2, 3] do
  {x * 2, sum + x}
end
</code></pre>
<p>The goal is to initialize variables to be used as state during the <code>for</code>. All variables initialized as part of the <code>for</code> must then be returned inside <code>do-end</code> block.</p>
<p>It may be slightly confusing in cases like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">sum = 0

for init(sum), x &lt;- [1, 2, 3] do
  {x * 2, sum + x}
end
</code></pre>
<p>But we can argue it is a shortcut for <code>init(sum = sum)</code>.</p>
<p>I don’t want to overreact but this may be my favorite option so far. <img src="https://forum.elixirforum.com/images/emoji/apple/sweat_smile.png?v=15" title=":sweat_smile:" class="emoji" alt=":sweat_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="237005" data-batch-url="/posts/batch_likers">
                        18
                      </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/introducing-for-let-and-for-reduce/44773/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-237005" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237005"
                     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 #27"></div>
  </section>
</div>
    <div class="postbit" id="237006" data-post-id="237006">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>It’s nice but it still does not convey the fact that the value is updated from the return tuple and the new value is reinjected on later iterations very well.</p>
<p>I was also thinking about this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  let sum = 0 in for x &lt;- [1, 2, 3] do
    {x * 2, sum + x}
  end
</code></pre>
<p>But it is not that explicit either.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237006" data-batch-url="/posts/batch_likers">
                        2
                      </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/introducing-for-let-and-for-reduce/44773/29">Post #28</a>
	                </div>
	            </div>
              <div id="likers-container-237006" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237006"
                     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 #28"></div>
  </section>
</div>
    <div class="postbit" id="237008" data-post-id="237008">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                    <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 class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Having <code>let</code> at the beginning is not an option. It has several downsides:</p>
<ol>
<li>
<p>It requires adding <code>let</code> as a special form will will most likely break some code</p>
</li>
<li>
<p>It may give the impression <code>let</code> is a general construct while it is only specific to for-comprehensions</p>
</li>
<li>
<p>It doesn’t answer how to handle <code>for reduce</code> and adding both <code>reduce</code> and <code>let</code> as special forms is even more likely to break existing code</p>
</li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237008" data-batch-url="/posts/batch_likers">
                        4
                      </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/introducing-for-let-and-for-reduce/44773/30">Post #29</a>
	                </div>
	            </div>
              <div id="likers-container-237008" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237008"
                     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 #29"></div>
  </section>
</div>
    <div class="postbit" id="237009" data-post-id="237009">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="28" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Oh, this discussion gave me another idea for a name, <code>init</code>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for init(sum = 0), x &lt;- [1, 2, 3] do
  {x * 2, sum + x}
end
</code></pre>
<p>The goal is to initialize variables to be used as state during the <code>for</code>. All variables initialized as part of the <code>for</code> must then be returned inside <code>do-end</code> block.</p>
</blockquote>
</aside>
<p>With that in mind, why not</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for var ..., x &lt;- y, do: ...
</code></pre>
<p>JavaScript had to introduce <code>let</code> because <code>var</code> was historically function scoped, they needed something else for block scoping,  but could not be change <code>var</code> scoping without breaking old code<br>
in Elixir everything is already block scoped.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237009" 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/introducing-for-let-and-for-reduce/44773/31">Post #30</a>
	                </div>
	            </div>
              <div id="likers-container-237009" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237009"
                     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 #30"></div>
  </section>
</div>
    <div class="postbit" id="237010" data-post-id="237010">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                    <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 class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="massimo" data-post="31" data-topic="44773">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/massimo/48/5555_2.png" class="avatar"> massimo:</div>
<blockquote>
<p>JavaScript had to introduce <code>let</code> because <code>var</code> was historically function scoped, they needed something else for block scoping, but could not be change <code>var</code> scoping without breaking old code in Elixir everything is already block scoped.</p>
</blockquote>
</aside>
<p>I don’t think <code>var</code> is any better than <code>let</code>, unfortunately. I would say it is worse, actually. <code>let</code> at least is used by both functional and imperative languages where in some of those it doesn’t have a notion of mutability attached to it. If we have something named <code>var</code>, I would expect it to go the fully mutable route (and that’s how some languages like Scala use 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="237010" 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/introducing-for-let-and-for-reduce/44773/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-237010" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237010"
                     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 #31"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/44773/load_more?page=4">Load more posts (93 remaining)</a>
</div></template></turbo-stream>