closures and they can recurse!!!
Some checks failed
Build / build (push) Failing after 1m35s
Test / build (push) Has been cancelled

This commit is contained in:
Chuck Smith
2024-03-14 20:08:40 -04:00
parent 78b560e457
commit cc78fee3c8
10 changed files with 640 additions and 39 deletions

View File

@@ -2,6 +2,7 @@ package ast
import (
"bytes"
"fmt"
"monkey/token"
"strings"
)
@@ -220,6 +221,7 @@ type FunctionLiteral struct {
Token token.Token // The 'fn' token
Parameters []*Identifier
Body *BlockStatement
Name string
}
func (fl *FunctionLiteral) expressionNode() {}
@@ -233,6 +235,9 @@ func (fl *FunctionLiteral) String() string {
}
out.WriteString(fl.TokenLiteral())
if fl.Name != "" {
out.WriteString(fmt.Sprintf("<%s>", fl.Name))
}
out.WriteString("(")
out.WriteString(strings.Join(params, ", "))
out.WriteString(") ")