/docs/reference/functions/compile.md
Markdown | 51 lines | 33 code | 18 blank | 0 comment | 0 complexity | bc1456d887e641c1e49bb436700b9625 MD5 | raw file
Possible License(s): Apache-2.0
- # Function compile
- Parse and compile an expression.
- Returns a an object with a function `eval([scope])` to evaluate the
- compiled expression.
- ## Syntax
- ```js
- var code = math.compile(expr)
- var codes = math.compile([expr1, expr2, expr3, ...])
- ```
- ### Parameters
- Parameter | Type | Description
- --------- | ---- | -----------
- `expr` | String | String[] | Matrix | The expression to be compiled
- ### Returns
- Type | Description
- ---- | -----------
- {eval: Function} | Array.<{eval: Function}> | code An object with the compiled expression
- ## Examples
- ```js
- var code = math.compile('sqrt(3^2 + 4^2)');
- code.eval(); // 5
- var scope = {a: 3, b: 4}
- var code = math.compile('a * b'); // 12
- code.eval(scope); // 12
- scope.a = 5;
- code.eval(scope); // 20
- var nodes = math.compile(['a = 3', 'b = 4', 'a * b']);
- nodes[2].eval(); // 12
- ```
- ## See also
- [parse](parse.md),
- [eval](eval.md)
- <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->