|
1 | 1 | ## [Unreleased] |
2 | 2 |
|
| 3 | +### New Features |
| 4 | + |
| 5 | +- **Custom Operator Compilation**: The `compile()` method now supports overriding |
| 6 | + operators to use function calls instead of native operators. This enables |
| 7 | + compilation of vector/matrix operations and custom domain-specific languages. |
| 8 | + Addresses #240. |
| 9 | + |
| 10 | + ```javascript |
| 11 | + // Override operators for vector operations |
| 12 | + const expr = ce.parse('v + w'); |
| 13 | + const compiled = expr.compile({ |
| 14 | + operators: { |
| 15 | + Add: ['add', 11], // Convert + to add() function |
| 16 | + Multiply: ['mul', 12] // Convert * to mul() function |
| 17 | + }, |
| 18 | + functions: { |
| 19 | + add: (a, b) => a.map((v, i) => v + b[i]), |
| 20 | + mul: (a, b) => a.map((v, i) => v * b[i]) |
| 21 | + } |
| 22 | + }); |
| 23 | + |
| 24 | + const result = compiled({ v: [1, 2, 3], w: [4, 5, 6] }); |
| 25 | + // → [5, 7, 9] |
| 26 | + ``` |
| 27 | + |
| 28 | + **Features**: |
| 29 | + - Override operators using an object mapping operator names to function names |
| 30 | + - Use a function to conditionally override operators |
| 31 | + - Function-name operators (e.g., `add`, `mul`) compile to function calls |
| 32 | + - Symbol operators (e.g., `+`, `-`) compile to infix operators |
| 33 | + - Works with both scalar and collection (vector/array) arguments |
| 34 | + - Partial overrides supported (only override some operators) |
| 35 | + |
3 | 36 | ### Improvements |
4 | 37 |
|
5 | 38 | - **Improved `ask()` Queries**: `ce.ask()` now matches patterns with wildcards |
6 | | - correctly, can answer common “bound” queries such as |
| 39 | + correctly, can answer common "bound" queries such as |
7 | 40 | `ask(["Greater", "x", "_k"])` and `ask(["Greater", "_x", "_k"])`, normalizes |
8 | 41 | inequality patterns for matching (e.g. `ask(["Greater", "_x", 0])`), and falls |
9 | 42 | back to `verify()` for closed predicates when the fact is known but not stored |
|
0 commit comments