diff --git a/evaluator/evaluator.go b/evaluator/evaluator.go index 9de8d4d..00c3307 100644 --- a/evaluator/evaluator.go +++ b/evaluator/evaluator.go @@ -40,6 +40,7 @@ func Eval(node ast.Node, env *object.Environment) object.Object { return object.NewFloat(node.Value) case *ast.Function: function := object.NewFunction( + node.Name, node.Parameters, env, node.Body, diff --git a/object/function.go b/object/function.go index 6d6ff7a..ba6c786 100644 --- a/object/function.go +++ b/object/function.go @@ -8,13 +8,15 @@ import ( ) type Function struct { + Name string Parameters []*ast.Identifier Body *ast.Block Env *Environment } -func NewFunction(params []*ast.Identifier, env *Environment, body *ast.Block) *Function { +func NewFunction(name string, params []*ast.Identifier, env *Environment, body *ast.Block) *Function { return &Function{ + Name: name, Parameters: params, Env: env, Body: body, @@ -31,6 +33,7 @@ func (f *Function) Inspect() string { } out.WriteString("def ") + out.WriteString(f.Name) out.WriteString("(") out.WriteString(strings.Join(params, ", ")) out.WriteString(") \n")