Skip to content
Open
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
23 changes: 23 additions & 0 deletions evaluator/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func getFns() map[string]*object.Builtin {
Types: []string{},
Fn: echoFn,
},
// echo_n(arg:"hello")
"echo_n": &object.Builtin{
Types: []string{},
Fn: echo_nFn,
},
// int(string:"123")
// int(number:"123")
"int": &object.Builtin{
Expand Down Expand Up @@ -766,6 +771,24 @@ func echoFn(tok token.Token, env *object.Environment, args ...object.Object) obj
return NULL
}

// echo_n(arg:"hello")
func echo_nFn(tok token.Token, env *object.Environment, args ...object.Object) object.Object {
if len(args) == 0 {
// allow echo() without crashing
return NULL
}
var arguments []interface{} = make([]interface{}, len(args)-1)
for i, d := range args {
if i > 0 {
arguments[i-1] = d.Inspect()
}
}

fmt.Fprintf(env.Writer, args[0].Inspect(), arguments...)

return NULL
}

// int(string:"123")
// int(number:123)
func intFn(tok token.Token, env *object.Environment, args ...object.Object) object.Object {
Expand Down