This PR builds on #30 to complete the abstraction layer for multi-mode evaluation support.
The engine now accepts abstract expr.Expression and reducer.Reducer types instead of concrete lambda types.
Add pkg/reducer/reducer.go with Reducer interface defining Reduce(expr.Expression, onStep) expr.Expression.
Add pkg/lambda/reducer.go with NormalOrderReducer that wraps the existing ReduceAll logic.
Update engine.Engine to store expr.Expression and reducer.Reducer instead of *lambda.Expression.
Update plugins to use expr.Expression.String() directly (no pointer dereference needed).
Update main and tests to instantiate NormalOrderReducer and pass it to the engine.
Decisions
The Reducer.Reduce method returns the final expression and calls onStep after each reduction step with the current state.
NormalOrderReducer type-asserts to lambda.Expression internally; other expression types are returned unchanged.
The engine updates its Expression field both during reduction (via onStep) and after completion.
Benefits
The engine is now fully decoupled from lambda-specific types.
New evaluation modes can be added by implementing expr.Expression and reducer.Reducer.
Plugins work with any expression type that implements expr.Expression.
Prepares the codebase for SKI combinators, typed lambda calculus, or other future modes.
## Description
This PR builds on #30 to complete the abstraction layer for multi-mode evaluation support.
The engine now accepts abstract `expr.Expression` and `reducer.Reducer` types instead of concrete lambda types.
- Add `pkg/reducer/reducer.go` with `Reducer` interface defining `Reduce(expr.Expression, onStep) expr.Expression`.
- Add `pkg/lambda/reducer.go` with `NormalOrderReducer` that wraps the existing `ReduceAll` logic.
- Update `engine.Engine` to store `expr.Expression` and `reducer.Reducer` instead of `*lambda.Expression`.
- Update plugins to use `expr.Expression.String()` directly (no pointer dereference needed).
- Update main and tests to instantiate `NormalOrderReducer` and pass it to the engine.
### Decisions
- The `Reducer.Reduce` method returns the final expression and calls `onStep` after each reduction step with the current state.
- `NormalOrderReducer` type-asserts to `lambda.Expression` internally; other expression types are returned unchanged.
- The engine updates its `Expression` field both during reduction (via `onStep`) and after completion.
## Benefits
- The engine is now fully decoupled from lambda-specific types.
- New evaluation modes can be added by implementing `expr.Expression` and `reducer.Reducer`.
- Plugins work with any expression type that implements `expr.Expression`.
- Prepares the codebase for SKI combinators, typed lambda calculus, or other future modes.
## Checklist
- [x] Code follows conventional commit format.
- [x] Branch follows naming convention (`<type>/<description>`).
- [x] Tests pass (if applicable).
- [ ] Documentation updated (if applicable).
Closes #30
Introduce reducer.Reducer interface and update the engine to use abstract
expr.Expression and reducer.Reducer types, enabling pluggable reduction
strategies.
- Add pkg/reducer/reducer.go with Reducer interface.
- Add pkg/lambda/reducer.go with NormalOrderReducer implementation.
- Update engine to accept expr.Expression and reducer.Reducer.
- Update plugins to use expr.Expression directly (no pointer dereference).
- Update main and tests to pass reducer to engine.
Closes#30
mvhutz
merged commit f8e1223463 into main2026-01-16 23:42:08 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Description
This PR builds on #30 to complete the abstraction layer for multi-mode evaluation support.
The engine now accepts abstract
expr.Expressionandreducer.Reducertypes instead of concrete lambda types.pkg/reducer/reducer.gowithReducerinterface definingReduce(expr.Expression, onStep) expr.Expression.pkg/lambda/reducer.gowithNormalOrderReducerthat wraps the existingReduceAlllogic.engine.Engineto storeexpr.Expressionandreducer.Reducerinstead of*lambda.Expression.expr.Expression.String()directly (no pointer dereference needed).NormalOrderReducerand pass it to the engine.Decisions
Reducer.Reducemethod returns the final expression and callsonStepafter each reduction step with the current state.NormalOrderReducertype-asserts tolambda.Expressioninternally; other expression types are returned unchanged.Expressionfield both during reduction (viaonStep) and after completion.Benefits
expr.Expressionandreducer.Reducer.expr.Expression.Checklist
<type>/<description>).Closes #30