title: Erlang: how can I reference an anonymous function from within the body?
body: <p>In <a href="http://en.wikipedia.org/wiki/Erlang_(programming_language)" rel="noreferrer">Erlang</a> is there a way reference the currently executing function)?</p>
  
  <p>That would be useful to spawn an infinite loop:</p>
  
  <pre><code>spawn(fun() -&gt; do_something, this_fun() end)
  </code></pre>
  
  <p>In JavaScript <code>arguments.callee</code> does just that, see the specification on <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Functions_and_function_scope/arguments/callee" rel="noreferrer">MDC</a>.</p>
  
  <p>Edit to answer a 'why would you do that': mostly curiosity; it is also useful to define a timer when prorotyping:</p>
  
  <pre><code>Self = self(),
  spawn(fun() -&gt; Self ! wake_up, receive after 1000 -&gt; nil end, this_fun() end),
  %% ...
  </code></pre>