From 5ff8892d13855827f2af30a5973a58d182bacce4 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 26 Dec 2025 00:04:41 -0500 Subject: [PATCH] style: no underscores in variable names --- pkg/lambda/reduce.go | 4 ++-- pkg/lambda/substitute.go | 10 +++++----- pkg/parser/parser.go | 32 ++++++++++++++++---------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pkg/lambda/reduce.go b/pkg/lambda/reduce.go index b09f624..95a5507 100644 --- a/pkg/lambda/reduce.go +++ b/pkg/lambda/reduce.go @@ -5,8 +5,8 @@ func ReduceOnce(e *Expression) bool { case *Abstraction: return ReduceOnce(&typed.Body) case *Application: - fn, fn_ok := typed.Abstraction.(*Abstraction) - if fn_ok { + fn, fnOk := typed.Abstraction.(*Abstraction) + if fnOk { Substitute(&fn.Body, fn.Parameter, typed.Argument) *e = fn.Body return true diff --git a/pkg/lambda/substitute.go b/pkg/lambda/substitute.go index 29e2308..8d12145 100644 --- a/pkg/lambda/substitute.go +++ b/pkg/lambda/substitute.go @@ -11,16 +11,16 @@ func Substitute(e *Expression, target string, replacement Expression) { return } - replacement_free_vars := GetFreeVariables(replacement) - if !replacement_free_vars.Has(typed.Parameter) { + replacementFreeVars := GetFreeVariables(replacement) + if !replacementFreeVars.Has(typed.Parameter) { Substitute(&typed.Body, target, replacement) return } used := GetFreeVariables(typed.Body) - used.Union(replacement_free_vars) - fresh_var := GenerateFreshName(used) - Rename(typed, typed.Parameter, fresh_var) + used.Union(replacementFreeVars) + freshVar := GenerateFreshName(used) + Rename(typed, typed.Parameter, freshVar) Substitute(&typed.Body, target, replacement) case *Application: Substitute(&typed.Abstraction, target, replacement) diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index b7cd84e..ce0b898 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -23,9 +23,9 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression, atoms := []string{} for { - atom, atom_err := i.Next() - if atom_err != nil { - return nil, fmt.Errorf("could not find parameter or terminator of function: %w", atom_err) + atom, atomErr := i.Next() + if atomErr != nil { + return nil, fmt.Errorf("could not find parameter or terminator of function: %w", atomErr) } else if atom.Type == tokenizer.TokenVariable { atoms = append(atoms, atom.Value) } else if atom.Type == tokenizer.TokenDot { @@ -39,9 +39,9 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression, return nil, fmt.Errorf("every function must have atleast one parameter (column %d)", token.Index) } - body, body_err := ParseExpression(i) - if body_err != nil { - return nil, fmt.Errorf("could not parse function body: %w", body_err) + body, bodyErr := ParseExpression(i) + if bodyErr != nil { + return nil, fmt.Errorf("could not parse function body: %w", bodyErr) } // Construction. @@ -52,29 +52,29 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression, return result, nil case tokenizer.TokenOpenParen: - fn, fn_err := ParseExpression(i) - if fn_err != nil { - return nil, fmt.Errorf("could not parse call function: %w", fn_err) + fn, fnErr := ParseExpression(i) + if fnErr != nil { + return nil, fmt.Errorf("could not parse call function: %w", fnErr) } args := []lambda.Expression{} for { - if next, next_err := i.Peek(); next_err == nil && next.Type == tokenizer.TokenCloseParen { + if next, nextErr := i.Peek(); nextErr == nil && next.Type == tokenizer.TokenCloseParen { break } - arg, arg_err := ParseExpression(i) - if arg_err != nil { - return nil, fmt.Errorf("could not parse call argument: %w", arg_err) + arg, argErr := ParseExpression(i) + if argErr != nil { + return nil, fmt.Errorf("could not parse call argument: %w", argErr) } args = append(args, arg) } - close, close_err := i.Next() - if close_err != nil { - return nil, fmt.Errorf("Could not parse call terminating parenthesis: %w", close_err) + close, closeErr := i.Next() + if closeErr != nil { + return nil, fmt.Errorf("Could not parse call terminating parenthesis: %w", closeErr) } else if close.Type != tokenizer.TokenCloseParen { return nil, fmt.Errorf("expected call terminating parenthesis, got '%v' (column %v)", close.Value, close.Index) }