README.md in dentaku-0.2.12 vs README.md in dentaku-0.2.13

- old
+ new

@@ -46,39 +46,72 @@ calculator.evaluate('5 + 3 * 2') => 11 calculator.evaluate('(5 + 3) * 2') => 16 -A number of functions are also supported. Okay, the number is currently two, -but more will be added soon. The current functions are `round` and `if`, and -they work like their counterparts in Excel: +A number of functions are also supported. Okay, the number is currently five, +but more will be added soon. The current functions are +`if`, `not`, `round`, `rounddown`, and `roundup`, and they work like their counterparts in Excel: calculator.evaluate('if (pears < 10, 10, 20)', :pears => 5) => 10 calculator.evaluate('if (pears < 10, 10, 20)', :pears => 15) => 20 -`Round` can be called with or without the number of decimal places: +`round`, `rounddown`, and `roundup` can be called with or without the number of decimal places: calculator.evaluate('round(8.2)') => 8 calculator.evaluate('round(8.2759, 2)') => 8.28 +`round` and `rounddown` round down, while `roundup` rounds up. If you're too lazy to be building calculator objects, there's a shortcut just for you: Dentaku('plums * 1.5', {:plums => 2}) => 3.0 -SUPPORTED OPERATORS AND FUNCTIONS +BUILT-IN OPERATORS AND FUNCTIONS --------------------------------- -Math: `+ - * /` -Logic: `< > <= >= <> != = AND OR NOT` -Functions: `IF ROUND` +Math: `+ - * / %` +Logic: `< > <= >= <> != = AND OR` +Functions: `IF NOT ROUND ROUNDDOWN ROUNDUP` + + +EXTERNAL FUNCTIONS +------------------ + +See `spec/external_function_spec.rb` for examples of how to add your own functions. + +The short, dense version: + +Each rule for an external function consists of three parts: the function's name, +a list of tokens describing its signature (parameters), and a lambda representing the +function's body. + +The function name should be passed as a symbol (for example, `:func`). + +The token list should consist of `:numeric` or `:string` if a single value of the named +type should be passed; `:non_group` or `:non_group_star` for grouped expressions. + +> (what's the difference? when would you use one instead of the other?) + +The function body should accept a list of parameters. Each function body will be passed +a sequence of tokens, in order: + +1. The function's name +2. A token representing the opening parenthesis +3. Tokens representing the parameter values, separated by tokens representing the commas between parameters +4. A token representing the closing parenthesis + +It should return a token (either `:numeric` or `:string`) representing the return value. + +Rules can be set individually using Calculator#add_rule, or en masse using Calculator#add_rules. + THANKS ------ Big thanks to [ElkStone Basements](http://www.elkstonebasements.com/) for