PageRenderTime 138ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/reference/functions/compile.md

https://github.com/husayt/mathjs
Markdown | 51 lines | 33 code | 18 blank | 0 comment | 0 complexity | bc1456d887e641c1e49bb436700b9625 MD5 | raw file
Possible License(s): Apache-2.0
  1. # Function compile
  2. Parse and compile an expression.
  3. Returns a an object with a function `eval([scope])` to evaluate the
  4. compiled expression.
  5. ## Syntax
  6. ```js
  7. var code = math.compile(expr)
  8. var codes = math.compile([expr1, expr2, expr3, ...])
  9. ```
  10. ### Parameters
  11. Parameter | Type | Description
  12. --------- | ---- | -----------
  13. `expr` | String | String[] | Matrix | The expression to be compiled
  14. ### Returns
  15. Type | Description
  16. ---- | -----------
  17. {eval: Function} &#124; Array.<{eval: Function}> | code An object with the compiled expression
  18. ## Examples
  19. ```js
  20. var code = math.compile('sqrt(3^2 + 4^2)');
  21. code.eval(); // 5
  22. var scope = {a: 3, b: 4}
  23. var code = math.compile('a * b'); // 12
  24. code.eval(scope); // 12
  25. scope.a = 5;
  26. code.eval(scope); // 20
  27. var nodes = math.compile(['a = 3', 'b = 4', 'a * b']);
  28. nodes[2].eval(); // 12
  29. ```
  30. ## See also
  31. [parse](parse.md),
  32. [eval](eval.md)
  33. <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->