Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[object/funtion] Missing name to use when inspect #143

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions evaluator/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion object/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down