cfengine/core — pull request #622 by tzz (2013-05-06 03:38:12+00:00)
Title: eval() function

Acceptance test and docs included. I have a question about memory management; see the TODO in `FnCallEval`. Also I think this function should return success with an empty string to CFE if there's an evaluation problem, but let me know what you think.

This function will evaluate simple prefix math expression. Here's an example showing most of the use cases:

```
body common control
{
bundlesequence => { run };
}

bundle agent run
{
vars:
"values[0]" string => "x"; # bad
"values[1]" string => "+ 200"; # bad
"values[2]" string => "+ 200 100";
"values[3]" string => "- 200 100";
"values[4]" string => "- - -"; # bad
"values[5]" string => "+ - 2 3 1";
"values[6]" string => ""; # bad
"values[7]" string => "/ 3 0"; # bad
"values[8]" string => "** 3 3";
"values[9]" string => "** -1 2.1"; # -nan but not an error
"values[10]" string => "sin 20";
"values[11]" string => "cos 20";
"values[12]" string => "asin 0.2";
"values[13]" string => "acos 0.2";
"values[14]" string => "tan 20";
"values[15]" string => "atan 0.2";
"values[16]" string => "log 0.2";
"values[17]" string => "log2 0.2";
"values[18]" string => "log10 0.2";
"values[19]" string => "% 20 3"; # remainder
"values[20]" string => "sqrt 0.2";
"values[21]" string => "ceil 3.5";
"values[22]" string => "floor 3.4";
"values[23]" string => "abs -3.4";
"values[24]" string => "== -3.4 -3.4";
"values[25]" string => "== -3.400000 -3.400001";
"values[26]" string => "e";
"values[27]" string => "pi";

"indices" slist => getindices("values");

"eval[$(indices)]" string => eval("$(values[$(indices)])", "math", "prefix");

reports:
"math/prefix eval('$(values[$(indices)])') = '$(eval[$(indices)])'";
}
```