diff --git a/evaluator/evaluator.go b/evaluator/evaluator.go index c017e20..3bb5c1a 100644 --- a/evaluator/evaluator.go +++ b/evaluator/evaluator.go @@ -82,8 +82,6 @@ func evalPrefixAtom(operator string, right object.Object) object.Object { switch operator { case "-": return evalMinusPrefix(right) - case "!": - return evalExclamationPrefix(right) default: return newError("unknown operator: %s%s", operator, right) } @@ -98,17 +96,6 @@ func evalMinusPrefix(right object.Object) object.Object { return &object.Integer{Value: -value} } -func evalExclamationPrefix(right object.Object) object.Object { - switch right { - case True: - return False - case False: - return True - default: - return newError("unknown operator: !%s", right) - } -} - func evalSymbol(symbol *ast.Symbol, env *object.Environment) object.Object { builtintFunc, ok := builtins[symbol.Value] if ok { diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index 77d23ad..cb180ea 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -138,16 +138,6 @@ func TestEvalBooleanExpression(t *testing.T) { input: "false", expected: false, }, - { - name: "negation of true", - input: "!true", - expected: false, - }, - { - name: "negation of false", - input: "!false", - expected: true, - }, { name: "equation symbol: return true", input: ` @@ -280,6 +270,28 @@ func TestEvalBooleanExpression(t *testing.T) { }`, expected: false, }, + { + name: "negation of true", + input: ` + { + "command": { + "symbol": "!", + "args": true + } + }`, + expected: false, + }, + { + name: "negation of false", + input: ` + { + "command": { + "symbol": "!", + "args": false + } + }`, + expected: true, + }, } for _, tt := range tests {