title: Erlang "unbound variable" when calling a function
body: <p>I am trying to pass an integer parameter N to <code>cake</code> and return a list of size N of the square of 2 (for the sake of example). e.g. bakery:cake(3) => [4,4,4]</p>
  
  <p>Here is what I have attempted so far:</p>
  
  <pre><code>-module(bakery).
  -export([cake/1]).
  
  Foo = fun(X) -&gt; X * X end.
  
  cake(0) -&gt; [];
  cake(N) when N &gt; 0 -&gt; [ Foo(2) | cake(N-1) ].
  </code></pre>
  
  <p>When I compile the code <code>c(bakery).</code> in erl however, I get the following error trace:</p>
  
  <pre><code>bakery.erl:4:  syntax error before: Foo
  bakery.erl:7:  variable 'Foo' is unbound
  error
  </code></pre>
  
  <p>I am still getting used to anonymous functions and erlang in general coming an object-oriented world. Any help would be appreciated.</p>