From 929fb5d6458e14c6655e12e8d6e6779b50f88c9a Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 14 Nov 2023 23:29:06 +0100 Subject: [PATCH] Env+Eval: Tweak (and) and (-) --- src/env/functions/operators.cpp | 7 ++++++- src/eval-special-form.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/env/functions/operators.cpp b/src/env/functions/operators.cpp index f40a6b3..98922a9 100644 --- a/src/env/functions/operators.cpp +++ b/src/env/functions/operators.cpp @@ -30,7 +30,8 @@ void Environment::loadOperators() ADD_FUNCTION( "-", { - if (SIZE() == 0) { + size_t length = SIZE(); + if (length == 0) { return makePtr(0); } @@ -38,6 +39,10 @@ void Environment::loadOperators() VALUE_CAST(number, Number, (*begin)); int64_t result = number->number(); + if (length == 1) { + return makePtr(-result); + } + // Skip the first node for (auto it = begin + 1; it != end; ++it) { VALUE_CAST(number, Number, (*it)); diff --git a/src/eval-special-form.cpp b/src/eval-special-form.cpp index 98a1728..edc75a0 100644 --- a/src/eval-special-form.cpp +++ b/src/eval-special-form.cpp @@ -184,7 +184,7 @@ ValuePtr Eval::evalTry(const ValueVector& nodes, EnvironmentPtr env) // (and 1 2 3) void Eval::evalAnd(const ValueVector& nodes, EnvironmentPtr env) { - ValuePtr result; + ValuePtr result = makePtr(Constant::True); for (auto node : nodes) { m_ast = node; m_env = env;