50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package saccharine
|
|
|
|
type Expression interface {
|
|
IsExpression()
|
|
}
|
|
|
|
/** ------------------------------------------------------------------------- */
|
|
|
|
type Abstraction struct {
|
|
Parameters []string
|
|
Body Expression
|
|
}
|
|
|
|
type Application struct {
|
|
Abstraction Expression
|
|
Arguments []Expression
|
|
}
|
|
|
|
type Atom struct {
|
|
Name string
|
|
}
|
|
|
|
type Clause struct {
|
|
Statements []Statement
|
|
Returns Expression
|
|
}
|
|
|
|
func (Abstraction) IsExpression() {}
|
|
func (Application) IsExpression() {}
|
|
func (Atom) IsExpression() {}
|
|
func (Clause) IsExpression() {}
|
|
|
|
/** ------------------------------------------------------------------------- */
|
|
|
|
func NewAbstraction(parameter []string, body Expression) *Abstraction {
|
|
return &Abstraction{Parameters: parameter, Body: body}
|
|
}
|
|
|
|
func NewApplication(abstraction Expression, arguments []Expression) *Application {
|
|
return &Application{Abstraction: abstraction, Arguments: arguments}
|
|
}
|
|
|
|
func NewAtom(name string) *Atom {
|
|
return &Atom{Name: name}
|
|
}
|
|
|
|
func NewClause(statements []Statement, returns Expression) *Clause {
|
|
return &Clause{Statements: statements, Returns: returns}
|
|
}
|