Browse Source

Env+Eval: Tweak (and) and (-)

master
Riyyi 6 months ago
parent
commit
929fb5d645
  1. 7
      src/env/functions/operators.cpp
  2. 2
      src/eval-special-form.cpp

7
src/env/functions/operators.cpp vendored

@ -30,7 +30,8 @@ void Environment::loadOperators()
ADD_FUNCTION(
"-",
{
if (SIZE() == 0) {
size_t length = SIZE();
if (length == 0) {
return makePtr<Number>(0);
}
@ -38,6 +39,10 @@ void Environment::loadOperators()
VALUE_CAST(number, Number, (*begin));
int64_t result = number->number();
if (length == 1) {
return makePtr<Number>(-result);
}
// Skip the first node
for (auto it = begin + 1; it != end; ++it) {
VALUE_CAST(number, Number, (*it));

2
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>(Constant::True);
for (auto node : nodes) {
m_ast = node;
m_env = env;

Loading…
Cancel
Save