<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="107387" data-post-id="107387">
  <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 meant something like this, but actually didn’t know that a simple unquote in a hardcoded functions body would still work.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule A do
    defmacro gen_funcs(list) do
        quote bind_quoted: [list: list] do
            # The following instead of bind_quoted wouldn't work
            # list = unquote(list)
            for {name, i} &lt;- Enum.with_index(list, 1) do
                def unquote(name)(), do: unquote(i)
            end
        end
    end
end
    
defmodule B do
    require A
    A.gen_funcs([:test, :unquote, :fragments])
end
    
IO.inspect(B.test()) # 1
IO.inspect(B.unquote()) # 2
IO.inspect(B.fragments()) # 3
</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="107387" 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/macro-expansion-order/18592/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-107387" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="107387"
                     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="107389" data-post-id="107389">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="7stud" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  7stud
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="12" data-topic="18592">
<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>but actually didn’t know that a simple unquote in a hardcoded functions body would still work.</p>
</blockquote>
</aside>
<p>Like I said:</p>
<blockquote>
<p><code>bind_quoted()</code>  does  <em>NOT</em> make the specified variables available inside a  <code>def</code>  in the quote block, where  <code>unquote()</code>  does.</p>
</blockquote> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="107389" 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/macro-expansion-order/18592/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-107389" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="107389"
                     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="107390" data-post-id="107390">
  <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
                  </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="7stud" data-post="11" data-topic="18592">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/7/57b2e6/48.png" class="avatar"> 7stud:</div>
<blockquote>
<p>I’m not sure what you are trying to say there, but I don’t need two levels of unquoting here:</p>
</blockquote>
</aside>
<p>The issue is that when you do that, you are changing the semantics of the code:</p>
<p>Imagine if someone use your <code>one</code> macro like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Using do
  import My
  x = 1
  one(x)
end
</code></pre>
<p>In your version, it is not going to work, because you are taking the variable <code>x</code> out of its context and putting it inside a function. The correct is to use bind_quoted and use the two-level unquoting:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule My do
  defmacro one(x) do
    quote bind_quoted: [x: x] do
      def show_in_one do
        IO.puts "The macro arg for one() was: #{unquote(x)}"
      end
    end
  end
end
</code></pre>
<p>EDIT: of course, the above depends if your macro wants to work with values or expressions but most macros (think Phoenix, Ecto, etc) do work on values.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="107390" 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/macro-expansion-order/18592/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-107390" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="107390"
                     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="107419" data-post-id="107419">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sasajuric" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/120/991_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sasajuric
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Elixir In Action</span>
			          </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="10" data-topic="18592">
<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 believe <a class="mention" href="/u/sasajuric" rel="nofollow">@sasajuric</a> talks about this in his series</p>
</blockquote>
</aside>
<p>I explained some simplified version in <a href="https://www.theerlangelist.com/article/macros_1" rel="noopener nofollow ugc">part 1</a> (“Compilation process”), and <a href="https://www.theerlangelist.com/article/macros_6" rel="noopener nofollow ugc">part 6</a> (“Order of expansion” and “Module-level friendly macros”). This was mostly based on my own intuition, some experiments, and bit of code analysis.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="107419" 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/macro-expansion-order/18592/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-107419" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="107419"
                     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>