Skip to content

Commit 6200dd4

Browse files
committed
feat: fix #240
1 parent 5ecb7bc commit 6200dd4

10 files changed

Lines changed: 1030 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
11
## [Unreleased]
22

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+
336
### Improvements
437

538
- **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
740
`ask(["Greater", "x", "_k"])` and `ask(["Greater", "_x", "_k"])`, normalizes
841
inequality patterns for matching (e.g. `ask(["Greater", "_x", 0])`), and falls
942
back to `verify()` for closed predicates when the fact is known but not stored

0 commit comments

Comments
 (0)