Files
lambda/pkg/lambda/reduce.go
M.V. Hutz 17d71da025 refactor: remove unnecessary comments from structural sharing implementation
Remove verbose inline and doc comments added in the structural sharing PR.
The code is self-explanatory and the comments were redundant.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-10 20:58:25 -05:00

28 lines
523 B
Go

package lambda
import "git.maximhutz.com/max/lambda/pkg/fifo"
func ReduceOnce(e *Expression) bool {
stack := fifo.New(e)
for !stack.Empty() {
top := stack.MustPop()
switch typed := (*top).(type) {
case *Abstraction:
stack.Push(&typed.body)
case *Application:
if fn, fnOk := typed.function.(*Abstraction); fnOk {
reduced := fn.body.Substitute(fn.parameter, typed.argument)
*top = reduced
return true
}
stack.Push(&typed.argument)
stack.Push(&typed.function)
}
}
return false
}