Files
lambda/pkg/lambda/is_free_variable.go
2026-02-09 20:10:40 -05:00

19 lines
479 B
Go

package lambda
import "fmt"
// IsFree returns true if the variable name n occurs free in the expression.
// This function does not mutate the input expression.
func IsFree(e Expression, n string) bool {
switch e := e.(type) {
case Variable:
return e.Name == n
case Abstraction:
return e.Parameter != n && IsFree(e.Body, n)
case Application:
return IsFree(e.Abstraction, n) || IsFree(e.Argument, n)
default:
panic(fmt.Errorf("unknown expression type: %v", e))
}
}