title: DDMathParser: How to define default values for variables
body: <p>I am using <code>DDMathParser</code> to parse formulas and calculate the results, which works great.</p>
  <p><strong>Question:</strong></p>
  <p>Is it possible to set variables to default values in case they do not exist in the substitution dictionary?</p>
  <p><strong>Example:</strong></p>
  <p>My formula <code>$a + $b</code> requires two variables <code>$a</code> and <code>$b</code>. However, my substitution dictionary contains only an value for variable key <code>a</code> (e.g. 1), but does not contain an key <code>b</code>.</p>
  <p>What would be the preferred way to define variable <code>b</code> to be <code>0</code> as default value and avoid the parsing error message <code>&quot;unable to resolve variable&quot;</code>?</p>
  <p>Thank you!</p>
  <h2>Edit</h2>
  <p>The way I am using <code>DDMathParser</code> is by looping over multiple formulas and providing the same variable substitution dictionary to each formula. Sometimes, I don't have values for the variables: In this case the variables (keys and values) would not be included in the dictionary.</p>
  <p>Depending on the formula itself, I would like to return <code>nil</code> as result for the formula if one of the variables does not exist (e.g. I don't have a value for <code>profit</code> and the formula is <code>$profit / $revenue</code>, I would like to return <code>nil</code> which I can convert to a <code>NSString</code> of <code>n/a</code> later) or set the variable to <code>0</code> if it is does not exist in the dictionary (e.g. for a formula like <code>$profitA + $profitB + $profitC</code>, I would like to assume <code>0</code> for any missing variables (<code>$profitA</code>, <code>$profitB</code> or <code>$profitC</code>).</p>
  <p>For this reason, I cannot use a generic solution, which always returns <code>0</code> or <code>nil</code>, but would need to put this logic in the formula (e.g. as a custom function).</p>