Files
lambda/pkg/saccharine/saccharine.go
M.V. Hutz 361f529bdc docs: document remaining packages and simplify AST types (#45)
## Summary

- Added doc comments across the codebase: `pkg/lambda`, `pkg/saccharine`, `pkg/codec`, `pkg/engine`, `pkg/iterator`, `pkg/set`, `pkg/convert`, `internal/registry`, and `cmd/lambda`.
- Made lambda and saccharine expression structs use public fields instead of getters, matching `go/ast` conventions.
- Removed superfluous constructors for saccharine and lambda expression/statement types in favor of struct literals.
- Consolidated saccharine token constructors into a single `NewToken` function.
- Removed the unused `trace` package.

## Test plan

- [x] `go build ./...` passes.
- [x] `go test ./...` passes.
- [ ] Verify `go doc` output renders correctly for documented packages.

Reviewed-on: #45
Co-authored-by: M.V. Hutz <git@maximhutz.me>
Co-committed-by: M.V. Hutz <git@maximhutz.me>
2026-02-10 01:15:41 +00:00

61 lines
1.6 KiB
Go

// Package saccharine defines the AST for the Saccharine language, a sugared
// lambda calculus with let bindings and multi-statement clauses.
package saccharine
// An Expression is a node in the Saccharine abstract syntax tree.
// It is a sealed interface; only types in this package may implement it.
type Expression interface {
expression()
}
// An Abstraction is a lambda expression with zero or more parameters.
// A zero-parameter abstraction is treated as a thunk.
type Abstraction struct {
Parameters []string
Body Expression
}
// An Application applies an expression to zero or more arguments.
type Application struct {
Abstraction Expression
Arguments []Expression
}
// An Atom is a named variable.
type Atom struct {
Name string
}
// A Clause is a sequence of statements followed by a return expression.
type Clause struct {
Statements []Statement
Returns Expression
}
func (Abstraction) expression() {}
func (Application) expression() {}
func (Atom) expression() {}
func (Clause) expression() {}
// A Statement is a declaration within a Clause.
// It is a sealed interface; only types in this package may implement it.
type Statement interface {
statement()
}
// A LetStatement binds a name (with optional parameters) to an expression.
type LetStatement struct {
Name string
Parameters []string
Body Expression
}
// A DeclareStatement evaluates an expression for its side effects within a
// clause.
type DeclareStatement struct {
Value Expression
}
func (LetStatement) statement() {}
func (DeclareStatement) statement() {}