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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I like these proposed syntax but agree that it is tricky to find a single, short word that coneys the meaning. I tend to prefer <code>let</code> and <code>acc</code> over the other suggestions, but I like <code>for with(x=0), i &lt;- stuff do</code> or something crazy like <code>for |x=0, y=0|, i &lt;- stuff do</code> myself.</p>
<p>I’m not put off by with being used elsewhere but unsure if it’s possible to have both. Other synonyms could be carrying, using, keeping, holding, rebinding…</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237147" 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/63">Post #62</a>
	                </div>
	            </div>
              <div id="likers-container-237147" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237147"
                     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 #62"></div>
  </section>
</div>
    <div class="postbit" id="237154" data-post-id="237154">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Since the beginning of this thread I’ve had a strong aversion to the use of <code>let</code> and I realise now it’s because in other functional languages <code>let</code> is used to introduce a binding which can’t be rebound. When I read <code>let</code> I see a value which will never change so I get some cognitive dissonance seeing it used in this proposal.</p>
<p>Regarding the example</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for let(sources),
    sub &lt;- subs,
    sub_formatter = Path.join(sub, ".formatter.exs"),
    File.exists?(sub_formatter) do
  formatter_opts = eval_file_with_keyword_list(sub_formatter)

  {formatter_opts_and_subs, sources} =
    eval_deps_and_subdirectories(:in_memory, [sub], formatter_opts, sources)

  {{sub, formatter_opts_and_subs}, sources}
end
</code></pre>
<p>As other’s have suggested using <code>map_reduce</code> does seem far clearer to me. When I see this I can understand that we’re using a particular type of for comprehension. It specifies how variables are bound, what they’re initialised to, what the folding function is and what the return shape is (I have a hard time associating all of this with <code>let</code>).</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for map_reduce(sources),
    sub &lt;- subs,
    sub_formatter = Path.join(sub, ".formatter.exs"),
    File.exists?(sub_formatter) do
  formatter_opts = eval_file_with_keyword_list(sub_formatter)

  {formatter_opts_and_subs, sources} =
    eval_deps_and_subdirectories(:in_memory, [sub], formatter_opts, sources)

  {{sub, formatter_opts_and_subs}, sources}
end
</code></pre>
<p>It also opens the door for other functions</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for group_by, x &lt;- 1..10, y &lt;- 1..10 do
  case {x &gt; 5, y &gt; 5} do
    {true, true} -&gt; :top_right
    {true, false} -&gt; :bottom_right
    {false, false} -&gt; :bottom_left
    {true, false} -&gt; :top_left
  end
end
</code></pre>
<p>(one advantage of having the function at the start vs the current keyword style is that you don’t need an associated value for the syntax to make sense i.e.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for x &lt;- 1..10, y &lt;- 1..10, group_by: ? do
</code></pre>
<p>I do still have some concerns about the rebinding being a bit mysterious but the examples are quite compelling so I can get behind just learning it as a new special form.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237154" 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/64">Post #63</a>
	                </div>
	            </div>
              <div id="likers-container-237154" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237154"
                     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 #63"></div>
  </section>
</div>
    <div class="postbit" id="237163" data-post-id="237163">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think the proposal overall is fantastic and very well thought through!</p>
<p><code>let</code> seems clear enough once you know what it does – I’m not a big fan of either <code>init</code> (too ambiguous) or <code>let</code> with parentheses (looks too much like an external function).</p>
<p>I wonder if we’re seeing the adoption of <code>let</code> as a common signal for scoped variable bindings in Elixir; after all it was recently introduced in heex templates recently (<code>&lt;.form let={f} for={@changeset} phx-change="validate" phx-submit="save"&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="237163" 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/65">Post #64</a>
	                </div>
	            </div>
              <div id="likers-container-237163" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237163"
                     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 #64"></div>
  </section>
</div>
    <div class="postbit" id="237166" data-post-id="237166">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="benwilson512" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/120/1457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  benwilson512
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Craft GraphQL APIs in Elixir with Absinthe</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="christhekeele" data-post="61" 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/christhekeele/48/1039_2.png" class="avatar"> christhekeele:</div>
<blockquote>
<p>I like <code>bind</code> because it means more literally “keep these things close together”, whereas <code>let</code> is a more dismissive, one-time thing.</p>
</blockquote>
</aside>
<p>I am largely happy with <code>let</code> but I think <code>bind</code> might be better for this reason. It communicates that you are binding and <code>(re)binding</code> the variable to the loop. +1 from me.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237166" data-batch-url="/posts/batch_likers">
                        6
                      </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/66">Post #65</a>
	                </div>
	            </div>
              <div id="likers-container-237166" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237166"
                     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 #65"></div>
  </section>
</div>
    <div class="postbit" id="237173" data-post-id="237173">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m sorry if I’m repeating someone else’s argument. This post already had 66 messages when I first saw it and I haven’t been able to read through the whole thing yet. The general sentiment I got from a quick look is that most people are in support of the proposal and what’s being discussed at this point are syntactical and implementation details.</p>
<p>I wanted to share an observation about the original post that starts with a problem statement but then goes on to present a new syntax without making a strong case for how it solves the original problem.</p>
<p>Jose’s solution to the traversal problem in Elixir:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{sections, _acc} =
  Enum.map_reduce(sections, {1, 1}, fn section, {section_counter, lesson_counter} -&gt;
    lesson_counter = if section["reset_lesson_position"], do: 1, else: lesson_counter

    {lessons, lesson_counter} =
      Enum.map_reduce(section["lessons"], lesson_counter, fn lesson, lesson_counter -&gt;
        {Map.put(lesson, "position", lesson_counter), lesson_counter + 1}
      end)

    section =
      section
      |&gt; Map.put("lessons", lessons)
      |&gt; Map.put("position", section_counter)

    {section, {section_counter + 1, lesson_counter}}
  end)
</code></pre>
<p>The new solution the uses <code>for let</code>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{sections, _acc} =
  for let {section_counter, lesson_counter} = {1, 1}, section &lt;- sections do
    lesson_counter = if section["reset_lesson_position"], do: 1, else: lesson_counter
    
    {lessons, lesson_counter} =
      for let lesson_counter, lesson &lt;- section["lessons"] do
        {Map.put(lesson, "position", lesson_counter), lesson_counter + 1}
      end
    
    section =
      section
      |&gt; Map.put("lessons", lessons)
      |&gt; Map.put("position", section_counter)

    {section, {section_counter + 1, lesson_counter}}
  end
</code></pre>
<p>They looks mostly the same: both have the same shape, the same nested “map-reduce” traversals. So all of the original observations Jose made about the first solution–lack of reassignment, lack of mutability–hold for the second one as well.</p>
<p>Ultimately, the question posed in the original post “Therefore, how can we move forward?” remains unanswered. To me it looks like there was a motivating example to showcase how the new proposal could by applied in practice, but by the time we got to the end of the proposal, the motivating example had been forgotten and turned out to be irrelevant to the discussion.</p>
<p>I don’t really get the rationale behind the additional syntax being more beginner-friendly. On the contrary, it seems to bring more dilution to the notion of “idiomatic Elixir” because different people will prefer using different constructs to do the same thing. For example,</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; sum = 0
iex&gt; count = 0
iex&gt; for let {sum, count}, i &lt;- [1, 2, 3] do
...&gt;   sum = sum + i
...&gt;   count = count + 1
...&gt;   {i * 2, {sum, count}}
...&gt; end
</code></pre>
<p>can already be written as</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Enum.map_reduce([1, 2, 3], {0, 0}, fn i, {sum, count} -&gt;
  sum = sum + i
  count = count + 1
  {i*2, {sum, count}}
end)
</code></pre>
<p>and the differences between the two are superficial.</p>
<p>So far, the interesting bits about the proposal are the possibilities Jose mentions towards the end of the original post, the ones that aren’t going to be supported initially. But the tradeoff of starting on the path towards those possibilities is making it more difficult to decide which way of writing any given piece of code is the preferred one, given that the number of alternatives keeps increasing.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237173" data-batch-url="/posts/batch_likers">
                        8
                      </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/67">Post #66</a>
	                </div>
	            </div>
              <div id="likers-container-237173" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237173"
                     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 #66"></div>
  </section>
</div>
    <div class="postbit" id="237175" data-post-id="237175">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Not meaning to derail the discussion but I just have a feeling that <code>for</code>’s self-containedness is what’s motivating the addition of new syntax. What if we could “break out” of its “do-end” box and start using it as part of idiomatic Elixir pipelines? This could be achieved by adding a way to get a stream out of <code>for</code>, say,</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{combinations, {sum, count}} =
  for(i &lt;- [1,2,3], j &lt;- [:a,:b,:c], as: :stream, do: {i, j})
  |&gt; Enum.map_reduce({0, 0}, fn {i, j}, {sum, count} -&gt;
    sum = sum + i
    count = count + 1
    [{i, j}, {sum, count}}
  end)
</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="237175" 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/68">Post #67</a>
	                </div>
	            </div>
              <div id="likers-container-237175" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237175"
                     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 #67"></div>
  </section>
</div>
    <div class="postbit" id="237176" data-post-id="237176">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi,</p>
<p>How about introducing something similar to <a href="https://gigamonkeys.com/book/loop-for-black-belts.html" rel="noopener nofollow ugc">LOOP macro in Lisp</a>? With some properties like :collecting, :maximize, etc. It would give a complete set of options to be generic for most cases. If that would be reduce or map would depend on the annotations made by the user. I’m curious how difficult it would be to write LOOP macro in Elixir? In fact I always saw list comprehensions as a smaller brother of Lisp’s LOOP macro. But maybe that was only me…</p>
<p>P.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237176" 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/69">Post #68</a>
	                </div>
	            </div>
              <div id="likers-container-237176" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237176"
                     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 #68"></div>
  </section>
</div>
    <div class="postbit" id="237183" data-post-id="237183">
  <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="alco" data-post="67" 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/alco/48/20034_2.png" class="avatar"> alco:</div>
<blockquote>
<p>Ultimately, the question posed in the original post “Therefore, how can we move forward?” remains unanswered.</p>
</blockquote>
</aside>
<p>Yes, they look quite similar, but that’s partially the point. If we introduce something too different, then it is ultimately going to be rejected because it is not similar to anything in Elixir.</p>
<p>At the same time, if it is too similar, then people may say “well, it doesn’t add much”. And overall that’s a hard line to balance.</p>
<aside class="quote no-group" data-username="alco" data-post="67" 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/alco/48/20034_2.png" class="avatar"> alco:</div>
<blockquote>
<p>To me it looks like there was a motivating example to showcase how the new proposal could by applied in practice, but by the time we got to the end of the proposal, the motivating example had been forgotten and turned out to be irrelevant to the discussion.</p>
</blockquote>
</aside>
<p>The motivating example brings two concerns:</p>
<ol>
<li>
<p>The current solution has too much noise</p>
</li>
<li>
<p>The current solution requires knowing precisely the magic incantation to solve the problem (the word <code>map_reduce</code>)</p>
</li>
</ol>
<p>If you go through the proposed guide and try to solve it with <code>Enum</code>, you are going to see that each step requires knowing a particular function. First you map, then you flat map, then flat map+map, then you filter, then you map reduce, etc. We have even discussed examples that have to use flat+map+reduce.</p>
<p>The whole point of <code>for</code> is that with the addition of two constructs (<code>let</code> and <code>reduce</code>), we can express almost everything in the Enum module. From <code>any?</code>, to <code>find_value</code>, to <code>flat_map_reduce</code>, to <code>map_reduce</code>, and to <code>reduce</code>, but without imposing all of this naming upfront. You have a single construct with one or two variations on top, and that’s it. Oh, and it also slightly reduces the amount of noise too!</p>
<aside class="quote no-group" data-username="alco" data-post="67" 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/alco/48/20034_2.png" class="avatar"> alco:</div>
<blockquote>
<p>On the contrary, it seems to bring more dilution to the notion of “idiomatic Elixir” because different people will prefer using different constructs to do the same thing.</p>
</blockquote>
</aside>
<p>This argument does not hold by itself because of this:</p>
<ol>
<li>
<p>Well, we already have recursion, so why have the functions in <code>Enum</code>?</p>
</li>
<li>
<p>Well, we already have <code>Enum</code>, so why have <code>for comprehension</code> in the fist place?</p>
</li>
</ol>
<p>Let’s say we go back in time and use this argument to not add <code>for</code> to the language. After all, <code>for</code> is a different construct for doing the same thing as <code>Enum</code>. Here is what would happen. We would have to rewrite this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    for {encoding1, value1} &lt;- alphabet,
        {encoding2, value2} &lt;- alphabet do
      encoding = bsl(encoding1, 8) + encoding2
      value = bsl(value1, shift) + value2
      [clause] = quote(do: (unquote(value) -&gt; unquote(encoding)))
      clause
    end
</code></pre>
<p>to this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    Enum.flat_map(alphabet, fn {encoding1, value1} -&gt;
      Enum.map(alphabet, fn {encoding2, value2} -&gt;
        encoding = bsl(encoding1, 8) + encoding2
        value = bsl(value1, shift) + value2
        [clause] = quote(do: (unquote(value) -&gt; unquote(encoding)))
        clause
      end)
    end)
</code></pre>
<p>From this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">      for %{pid: pid} &lt;- files,
          {_, _, ref, ^pid, on, _, _} &lt;- waiting,
          not defining?(on, waiting),
          do: {ref, :not_found}
</code></pre>
<p>to this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">      Enum.flat_map(files, fn %{pid: pid} -&gt;
        waiting
        |&gt; Enum.filter(fn {_, _, ref, waiting_pid, on, _, _} -&gt; waiting_pid == pid end)
        |&gt; Enum.filter(fn {_, _, _, _, on, _, _} -&gt; not defining?(on, waiting) end)
        |&gt; Enum.map(fn {_, _, ref, _, _, _, _} -&gt; {ref, :not_found} end)
      end)
</code></pre>
<p>From this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">      for {pair, _, meta, _} &lt;- all_defined,
          {local, line, macro_dispatch?} &lt;- out_neighbours(bag, {:local, pair}),
          error = undefined_local_error(set, local, macro_dispatch?),
          do: {build_meta(line, meta), local, error}
</code></pre>
<p>to this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">      Enum.flat_map(all_defined, fn {pair, _, meta, _} -&gt;
        Enum.map(out_neighbours(bag, {:local, pair}), fn {local, line, macro_dispatch?} -&gt;
          error = undefined_local_error(set, local, macro_dispatch?)
          {build_meta(line, meta), local, error}
        end)
        |&gt; Enum.filter(fn {meta, local, error} -&gt; error != nil end)
      end)
</code></pre>
<p>From this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">          for path &lt;- Mix.Dep.load_paths(dep),
              beam &lt;- Path.wildcard(Path.join(path, "*.beam")),
              Mix.Utils.last_modified(beam) &gt; modified,
              reduce: {modules, exports, new_exports} do
            {modules, exports, new_exports} -&gt;
              ...
              {modules, exports, new_exports}
          end
</code></pre>
<p>to this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">          Enum.reduce(Mix.Dep.load_paths(dep), {modules, exports, new_exports}, fn path, acc -&gt;
            Path.wildcard(Path.join(path, "*.beam"))
            |&gt; Enum.filter(&amp;Mix.Utils.last_modified(&amp;1) &gt; modified)
            |&gt; Enum.reduce(acc, fn beam, {modules, exports, new_exports} -&gt;
              ...
              {modules, exports, new_exports}
            end)
          end
</code></pre>
<p>I could go on and on. If we didn’t have <code>for</code>, all of those snippets would be <strong>worse, noisier, and also slower</strong>.</p>
<p>And I didn’t have to look hard either. Those examples came all from <code>lib/elixir/lib</code>, with the exception of the last one were I grepped for <code>reduce: </code>. I am sure you will find several others there, all in a single repository.</p>
<p>So my point is: yes, they ultimately achieve the same thing, but <code>for</code> comprehensions have always enabled us to write complex traversals quite more elegantly than the <code>Enum</code> module. If someone asked me what is Idiomatic Elixir, I would take <code>for</code> over <code>Enum</code>, whenever that’s possible. The same way I take <code>Enum</code> over manual recursion. This proposal allows us to use <code>for</code> in places where we can’t right now and that’s bound to bring the same benefits as we have seen in the snippets above. <a href="https://forum.elixirforum.com/t/introducing-for-let-and-for-reduce/44773/57" rel="nofollow">I have already posted examples of how the proposal can improve existing code</a>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="237183" data-batch-url="/posts/batch_likers">
                        13
                      </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/70">Post #69</a>
	                </div>
	            </div>
              <div id="likers-container-237183" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237183"
                     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 #69"></div>
  </section>
</div>
    <div class="postbit" id="237190" data-post-id="237190">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Just wanted to throw my 0.02c onto the discussion. At first I didn’t like the proposed changes, but the more I’ve read this thread and let it sit with me the more it’s grown on me. I would like to express my support for two proposals others have made, namely I like <code>bind</code> over <code>let</code>, and I also think that it should require parenthesis. So to me, this is ideal in terms of readability of all the proposed options.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">for bind({x, y} = {0, 0}), i &lt;- [1, 2, 3] do
  {i, {x + i, y + i + 1}}
end
</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="237190" 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/71">Post #70</a>
	                </div>
	            </div>
              <div id="likers-container-237190" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237190"
                     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 #70"></div>
  </section>
</div>
    <div class="postbit" id="237193" data-post-id="237193">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Along with the required parentheses, an option to cover both map reduce and reduce without a separate word could be to add something like <code>:returning</code>. This could default to <code>:map_reduce</code>, but be set to <code>:reduce</code> as needed.</p>
<p>Map Reduce</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; for let(sum = 0), i &lt;- [1, 2, 3] do
...&gt;   sum = sum + i
...&gt;   {i * 2, sum}
...&gt; end
{[2, 4, 6], 6}
</code></pre>
<p>Reduce</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; for let(sum = 0, returning: :reduce), i &lt;- [1, 2, 3] do
...&gt;   sum + i
...&gt; end
6
</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="237193" 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/introducing-for-let-and-for-reduce/44773/72">Post #71</a>
	                </div>
	            </div>
              <div id="likers-container-237193" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="237193"
                     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 #71"></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=8">Load more posts (53 remaining)</a>
</div></template></turbo-stream>