title: Understanding lambdas in pystache
body: <p>Say I want to write a function that format floats with 2 digits in pystache.</p>
  
  <p>I want both the float number and the function in the context (I believe this is the correct philosophy of Mustache).</p>
  
  <p>What should I do?</p>
  
  <p>In order to make the problem clear, I will show a pair of code snippets I have written. They do not work.</p>
  
  <p>Snippet (a):</p>
  
  <pre><code>import pystache
  
  tpl = "{{#fmt}}{{q}}{{/fmt}}"
  
  ctx = {
      'q' : 1234.5678,
      'fmt' : lambda x: "%.2f" % float(x)
  }
  
  print pystache.render(tpl, ctx)
  </code></pre>
  
  <p>This fails, with error "could not convert string to float: {{q}}". I can understand this error: {{fmt}} is evaluated before {{q}}.</p>
  
  <p>Snippet (b):</p>
  
  <pre><code>import pystache
  
  tpl = "{{#q}}{{fmt}}{{/q}}"
  
  ctx = {
      'q' : 1234.5678,
      'fmt' : lambda x: "%.2f" % float(x)
  }
  
  print pystache.render(tpl, ctx)
  </code></pre>
  
  <p>This fails with error: "lambda() takes exactly 1 argument (0 given)". I can't understand this error: shouldn't the context be passed as argument?</p>