From 1f486875fd3e104b9167ae8d801161db031c8ed6 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Sat, 7 Feb 2026 15:26:50 +0000 Subject: [PATCH] style: rename repr to expr (#44) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description The `Repr` type name was unclear — it was intended to represent a lambda calculus expression, not a "representation." This PR renames `Repr` to `Expr` throughout the registry package for clarity. - Rename `Repr` interface to `Expr` and `baseRepr` struct to `baseExpr`. - Rename `repr.go` to `expr.go`. - Rename `ID()` method to `Repr()` to indicate the representation type. - Rename `NewRepr` constructor to `NewExpr`. - Update all usages in codec, conversion, engine, process, and registry files. - Add command aliases `conv` and `eng` for `convert` and `engine` subcommands. ## Benefits - The naming better reflects the domain: an `Expr` is an expression, and `Repr()` returns its representation kind. - Command aliases reduce typing for common subcommands. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (`/`). Always use underscores. - [x] Tests pass (if applicable). - [x] Documentation updated (if applicable). Reviewed-on: https://git.maximhutz.com/mvhutz/lambda/pulls/44 Co-authored-by: M.V. Hutz Co-committed-by: M.V. Hutz --- cmd/lambda/lambda_convert.go | 1 + cmd/lambda/lambda_engine.go | 5 +++-- internal/registry/codec.go | 8 ++++---- internal/registry/conversion.go | 8 ++++---- internal/registry/engine.go | 8 ++++---- internal/registry/expr.go | 24 ++++++++++++++++++++++++ internal/registry/process.go | 6 +++--- internal/registry/registry.go | 20 +++++++++++--------- internal/registry/repr.go | 24 ------------------------ 9 files changed, 54 insertions(+), 50 deletions(-) create mode 100644 internal/registry/expr.go delete mode 100644 internal/registry/repr.go diff --git a/cmd/lambda/lambda_convert.go b/cmd/lambda/lambda_convert.go index b2fd20c..3dc0a6f 100644 --- a/cmd/lambda/lambda_convert.go +++ b/cmd/lambda/lambda_convert.go @@ -26,6 +26,7 @@ func LambdaConvert() *cobra.Command { cmd := &cobra.Command{ Use: "convert ", + Aliases: []string{"conv"}, Short: "Convert between lambda calculus representations", SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/lambda/lambda_engine.go b/cmd/lambda/lambda_engine.go index b8a2f35..150e851 100644 --- a/cmd/lambda/lambda_engine.go +++ b/cmd/lambda/lambda_engine.go @@ -6,8 +6,9 @@ import ( func LambdaEngine() *cobra.Command { cmd := &cobra.Command{ - Use: "engine", - Short: "Information about available engines", + Use: "engine", + Aliases: []string{"eng"}, + Short: "Information about available engines", RunE: func(cmd *cobra.Command, args []string) error { return cmd.Help() }, diff --git a/internal/registry/codec.go b/internal/registry/codec.go index f23da98..302d3d6 100644 --- a/internal/registry/codec.go +++ b/internal/registry/codec.go @@ -8,7 +8,7 @@ import ( ) type Codec interface { - codec.Codec[Repr] + codec.Codec[Expr] InType() string } @@ -18,16 +18,16 @@ type convertedCodec[T any] struct { inType string } -func (c convertedCodec[T]) Decode(s string) (Repr, error) { +func (c convertedCodec[T]) Decode(s string) (Expr, error) { t, err := c.codec.Decode(s) if err != nil { return nil, err } - return NewRepr(c.inType, t), nil + return NewExpr(c.inType, t), nil } -func (c convertedCodec[T]) Encode(r Repr) (string, error) { +func (c convertedCodec[T]) Encode(r Expr) (string, error) { t, ok := r.Data().(T) if !ok { dataType := reflect.TypeOf(r.Data()) diff --git a/internal/registry/conversion.go b/internal/registry/conversion.go index b793ed2..d5b4d13 100644 --- a/internal/registry/conversion.go +++ b/internal/registry/conversion.go @@ -10,7 +10,7 @@ type Conversion interface { InType() string OutType() string - Run(Repr) (Repr, error) + Run(Expr) (Expr, error) } type convertedConversion[T, U any] struct { @@ -18,8 +18,8 @@ type convertedConversion[T, U any] struct { inType, outType string } -func (c convertedConversion[T, U]) Run(r Repr) (Repr, error) { - t, ok := r.Data().(T) +func (c convertedConversion[T, U]) Run(expr Expr) (Expr, error) { + t, ok := expr.Data().(T) if !ok { return nil, fmt.Errorf("could not parse '%v' as '%s'", t, c.inType) } @@ -29,7 +29,7 @@ func (c convertedConversion[T, U]) Run(r Repr) (Repr, error) { return nil, err } - return NewRepr(c.outType, u), nil + return NewExpr(c.outType, u), nil } func (c convertedConversion[T, U]) InType() string { return c.inType } diff --git a/internal/registry/engine.go b/internal/registry/engine.go index 16b162c..9931916 100644 --- a/internal/registry/engine.go +++ b/internal/registry/engine.go @@ -7,7 +7,7 @@ import ( ) type Engine interface { - Load(Repr) (Process, error) + Load(Expr) (Process, error) Name() string InType() string } @@ -22,10 +22,10 @@ func (e convertedEngine[T]) InType() string { return e.inType } func (e convertedEngine[T]) Name() string { return e.name } -func (e convertedEngine[T]) Load(r Repr) (Process, error) { - t, ok := r.Data().(T) +func (e convertedEngine[T]) Load(expr Expr) (Process, error) { + t, ok := expr.Data().(T) if !ok { - return nil, fmt.Errorf("'ncorrent format '%s' for engine '%s'", r.ID(), e.inType) + return nil, fmt.Errorf("'ncorrent format '%s' for engine '%s'", expr.Repr(), e.inType) } process, err := e.engine(t) diff --git a/internal/registry/expr.go b/internal/registry/expr.go new file mode 100644 index 0000000..49377ae --- /dev/null +++ b/internal/registry/expr.go @@ -0,0 +1,24 @@ +package registry + +// A Expr is a lambda calculus expression. It can have any type of +// Expresentation, so long as that class is known to the registry it is handled +// by. +type Expr interface { + // Repr returns the name of the underlying Expresentation. It is assumed if + // two expressions have the same Repr(), they have the same Expresentation. + Repr() string + + // The base expression data. + Data() any +} + +type baseExpr struct { + id string + data any +} + +func (r baseExpr) Repr() string { return r.id } + +func (r baseExpr) Data() any { return r.data } + +func NewExpr(id string, data any) Expr { return baseExpr{id, data} } diff --git a/internal/registry/process.go b/internal/registry/process.go index d2150dd..9e4a0f0 100644 --- a/internal/registry/process.go +++ b/internal/registry/process.go @@ -5,7 +5,7 @@ import ( ) type Process interface { - engine.Process[Repr] + engine.Process[Expr] InType() string } @@ -17,13 +17,13 @@ type convertedProcess[T any] struct { func (e convertedProcess[T]) InType() string { return e.inType } -func (b convertedProcess[T]) Get() (Repr, error) { +func (b convertedProcess[T]) Get() (Expr, error) { s, err := b.process.Get() if err != nil { return nil, err } - return NewRepr(b.inType, s), nil + return NewExpr(b.inType, s), nil } func (b convertedProcess[T]) Step(i int) bool { diff --git a/internal/registry/registry.go b/internal/registry/registry.go index dea5d34..ecbf28f 100644 --- a/internal/registry/registry.go +++ b/internal/registry/registry.go @@ -40,16 +40,18 @@ func (r *Registry) GetDefaultEngine(id string) (Engine, error) { } } - return nil, fmt.Errorf("no engine for '%s'", id) + return r.GetEngine("normalorder") + + // return nil, fmt.Errorf("no engine for '%s'", id) } -func (r *Registry) ConvertTo(repr Repr, outType string) (Repr, error) { - path, err := r.ConversionPath(repr.ID(), outType) +func (r *Registry) ConvertTo(expr Expr, outType string) (Expr, error) { + path, err := r.ConversionPath(expr.Repr(), outType) if err != nil { return nil, err } - result := repr + result := expr for _, conversion := range path { result, err = conversion.Run(result) if err != nil { @@ -60,16 +62,16 @@ func (r *Registry) ConvertTo(repr Repr, outType string) (Repr, error) { return result, err } -func (r *Registry) Marshal(repr Repr) (string, error) { - m, ok := r.codecs[repr.ID()] +func (r *Registry) Marshal(expr Expr) (string, error) { + m, ok := r.codecs[expr.Repr()] if !ok { - return "", fmt.Errorf("no marshaler for '%s'", repr.ID()) + return "", fmt.Errorf("no marshaler for '%s'", expr.Repr()) } - return m.Encode(repr) + return m.Encode(expr) } -func (r *Registry) Unmarshal(s string, outType string) (Repr, error) { +func (r *Registry) Unmarshal(s string, outType string) (Expr, error) { m, ok := r.codecs[outType] if !ok { return nil, fmt.Errorf("no marshaler for '%s'", outType) diff --git a/internal/registry/repr.go b/internal/registry/repr.go deleted file mode 100644 index 1288f3c..0000000 --- a/internal/registry/repr.go +++ /dev/null @@ -1,24 +0,0 @@ -package registry - -// A Repr is a lambda calculus expression. It can have any type of -// representation, so long as that class is known to the registry it is handled -// by. -type Repr interface { - // ID returns the name of the underlying representation. It is assumed that - // if two expressions have the same Id(), they have the same representation. - ID() string - - // The base expression data. - Data() any -} - -type baseRepr struct { - id string - data any -} - -func (r baseRepr) ID() string { return r.id } - -func (r baseRepr) Data() any { return r.data } - -func NewRepr(id string, data any) Repr { return baseRepr{id, data} }