refactor: rename Application.function field to Application.abstraction

Changed the Application struct field from 'function' to 'abstraction' for semantic clarity and consistency with the lambda calculus terminology.

Updated all references across the codebase including the getter method, constructor parameter, and usages in substitute, rename, reduce, get_free_variables, is_free_variable, and stringify functions.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-10 21:09:35 -05:00
parent ae2ce6fd2f
commit fea749591c
7 changed files with 17 additions and 17 deletions

View File

@@ -30,12 +30,12 @@ func NewAbstraction(parameter string, body Expression) *Abstraction {
/** ------------------------------------------------------------------------- */
type Application struct {
function Expression
argument Expression
abstraction Expression
argument Expression
}
func (a *Application) Function() Expression {
return a.function
func (a *Application) Abstraction() Expression {
return a.abstraction
}
func (a *Application) Argument() Expression {
@@ -46,8 +46,8 @@ func (a *Application) Accept(v Visitor) {
v.VisitApplication(a)
}
func NewApplication(function Expression, argument Expression) *Application {
return &Application{function: function, argument: argument}
func NewApplication(abstraction Expression, argument Expression) *Application {
return &Application{abstraction: abstraction, argument: argument}
}
/** ------------------------------------------------------------------------- */

View File

@@ -11,7 +11,7 @@ func GetFreeVariables(e Expression) *set.Set[string] {
vars.Remove(e.parameter)
return vars
case *Application:
vars := GetFreeVariables(e.function)
vars := GetFreeVariables(e.abstraction)
vars.Merge(GetFreeVariables(e.argument))
return vars
default:

View File

@@ -7,7 +7,7 @@ func IsFreeVariable(n string, e Expression) bool {
case *Abstraction:
return e.parameter != n && IsFreeVariable(n, e.body)
case *Application:
return IsFreeVariable(n, e.function) || IsFreeVariable(n, e.argument)
return IsFreeVariable(n, e.abstraction) || IsFreeVariable(n, e.argument)
default:
return false
}

View File

@@ -12,14 +12,14 @@ func ReduceOnce(e *Expression) bool {
case *Abstraction:
stack.Push(&typed.body)
case *Application:
if fn, fnOk := typed.function.(*Abstraction); fnOk {
if fn, fnOk := typed.abstraction.(*Abstraction); fnOk {
reduced := Substitute(fn.body, fn.parameter, typed.argument)
*top = reduced
return true
}
stack.Push(&typed.argument)
stack.Push(&typed.function)
stack.Push(&typed.abstraction)
}
}

View File

@@ -23,14 +23,14 @@ func Rename(expr Expression, target string, newName string) Expression {
return NewAbstraction(newParam, newBody)
case *Application:
newFunc := Rename(e.function, target, newName)
newAbs := Rename(e.abstraction, target, newName)
newArg := Rename(e.argument, target, newName)
if newFunc == e.function && newArg == e.argument {
if newAbs == e.abstraction && newArg == e.argument {
return e
}
return NewApplication(newFunc, newArg)
return NewApplication(newAbs, newArg)
default:
return expr

View File

@@ -19,7 +19,7 @@ func (v *stringifyVisitor) VisitAbstraction(f *Abstraction) {
func (v *stringifyVisitor) VisitApplication(c *Application) {
v.builder.WriteRune('(')
c.function.Accept(v)
c.abstraction.Accept(v)
v.builder.WriteRune(' ')
c.argument.Accept(v)
v.builder.WriteRune(')')

View File

@@ -31,14 +31,14 @@ func Substitute(expr Expression, target string, replacement Expression) Expressi
return NewAbstraction(param, newBody)
case *Application:
newFunc := Substitute(e.function, target, replacement)
newAbs := Substitute(e.abstraction, target, replacement)
newArg := Substitute(e.argument, target, replacement)
if newFunc == e.function && newArg == e.argument {
if newAbs == e.abstraction && newArg == e.argument {
return e
}
return NewApplication(newFunc, newArg)
return NewApplication(newAbs, newArg)
default:
return expr