refactor: make lambda expression types immutable (#38)

## Summary

- Change Abstraction, Application, and Variable to use private fields with getter methods.
- Return value types instead of pointers from constructors.
- Update all type switches to match value types instead of pointer types.

## Test plan

- [x] All existing tests pass (`make test`).

Reviewed-on: #38
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>
This commit was merged in pull request #38.
This commit is contained in:
2026-01-17 22:00:54 +00:00
committed by Maxim Hutz
parent c2aa77cb92
commit e85cf7ceff
21 changed files with 191 additions and 255 deletions

View File

@@ -34,34 +34,34 @@ func main() {
logger.Info("compiled λ expression", "tree", compiled.String())
// Create reducer with the compiled expression.
reducer := lambda.NewNormalOrderReducer(&compiled)
interpreter := lambda.NewInterpreter(compiled)
// If the user selected to track CPU performance, attach a profiler.
if options.Profile != "" {
plugins.NewPerformance(options.Profile, reducer)
plugins.NewPerformance(options.Profile, interpreter)
}
// If the user selected to produce a step-by-step explanation, attach an
// observer.
if options.Explanation {
plugins.NewExplanation(reducer)
plugins.NewExplanation(interpreter)
}
// If the user opted to track statistics, attach a tracker.
if options.Statistics {
plugins.NewStatistics(reducer)
plugins.NewStatistics(interpreter)
}
// If the user selected for verbose debug logs, attach a reduction tracker.
if options.Verbose {
plugins.NewLogs(logger, reducer)
plugins.NewLogs(logger, interpreter)
}
// Run reduction.
reducer.Reduce()
interpreter.Run()
// Return the final reduced result.
result := reducer.Expression().String()
result := interpreter.Expression().String()
err = options.Destination.Write(result)
cli.HandleError(err)
}

View File

@@ -30,8 +30,8 @@ func runSample(samplePath string) (string, error) {
compiled := convert.SaccharineToLambda(ast)
// Create and run the reducer.
reducer := lambda.NewNormalOrderReducer(&compiled)
reducer.Reduce()
reducer := lambda.NewInterpreter(compiled)
reducer.Run()
return reducer.Expression().String() + "\n", nil
}