Skip to content

Commit

Permalink
add builtin function for negation (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Sep 30, 2024
1 parent df37652 commit ebd5e48
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions evaluator/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,13 @@ var builtins = map[string]*object.Builtin{
return True
},
},
"!": {
Fn: func(args object.Object) object.Object {
if args.Type() != object.BOOLEAN_OBJ {
return newError("argument to '!' must be BOOLEAN, got %s", args.Type())
}

return &object.Boolean{Value: !args.(*object.Boolean).Value}
},
},
}

0 comments on commit ebd5e48

Please sign in to comment.