Closes #26 - Added -i flag to select interpreter (lambda or debruijn) - Created debruijn package with Expression interface - Variable contains index and optional label - Abstraction contains only body (no parameter) - Application structure remains similar - Implemented De Bruijn reduction without variable renaming - Shift operation handles index adjustments - Substitute replaces by index instead of name - Abstracted Engine into interface with two implementations - LambdaEngine: original named variable engine - DeBruijnEngine: new index-based engine - Added conversion functions between representations - LambdaToDeBruijn: converts named to indexed - DeBruijnToLambda: converts indexed back to named - SaccharineToDeBruijn: direct saccharine to De Bruijn - Updated main to switch engines based on -i flag - All test samples pass with both engines Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
25 lines
623 B
Go
25 lines
623 B
Go
// Package "engine" provides an extensible interface for users to interfact with
|
|
// λ-calculus.
|
|
package engine
|
|
|
|
import (
|
|
"git.maximhutz.com/max/lambda/internal/config"
|
|
"git.maximhutz.com/max/lambda/pkg/emitter"
|
|
)
|
|
|
|
// Engine is an interface for reduction engines.
|
|
type Engine interface {
|
|
Run()
|
|
GetResult() string
|
|
On(message string, fn func()) *emitter.Observer
|
|
Emit(message string)
|
|
}
|
|
|
|
// New creates the appropriate engine based on the config.
|
|
func New(cfg *config.Config, input interface{}) Engine {
|
|
if cfg.Interpreter == "debruijn" {
|
|
return NewDeBruijnEngine(cfg, input)
|
|
}
|
|
return NewLambdaEngine(cfg, input)
|
|
}
|