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>
28 lines
523 B
Go
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
|
|
}
|