Env+Eval: Tweak (and) and (-)
This commit is contained in:
Vendored
+6
-1
@@ -30,7 +30,8 @@ void Environment::loadOperators()
|
|||||||
ADD_FUNCTION(
|
ADD_FUNCTION(
|
||||||
"-",
|
"-",
|
||||||
{
|
{
|
||||||
if (SIZE() == 0) {
|
size_t length = SIZE();
|
||||||
|
if (length == 0) {
|
||||||
return makePtr<Number>(0);
|
return makePtr<Number>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +39,10 @@ void Environment::loadOperators()
|
|||||||
VALUE_CAST(number, Number, (*begin));
|
VALUE_CAST(number, Number, (*begin));
|
||||||
int64_t result = number->number();
|
int64_t result = number->number();
|
||||||
|
|
||||||
|
if (length == 1) {
|
||||||
|
return makePtr<Number>(-result);
|
||||||
|
}
|
||||||
|
|
||||||
// Skip the first node
|
// Skip the first node
|
||||||
for (auto it = begin + 1; it != end; ++it) {
|
for (auto it = begin + 1; it != end; ++it) {
|
||||||
VALUE_CAST(number, Number, (*it));
|
VALUE_CAST(number, Number, (*it));
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ ValuePtr Eval::evalTry(const ValueVector& nodes, EnvironmentPtr env)
|
|||||||
// (and 1 2 3)
|
// (and 1 2 3)
|
||||||
void Eval::evalAnd(const ValueVector& nodes, EnvironmentPtr env)
|
void Eval::evalAnd(const ValueVector& nodes, EnvironmentPtr env)
|
||||||
{
|
{
|
||||||
ValuePtr result;
|
ValuePtr result = makePtr<Constant>(Constant::True);
|
||||||
for (auto node : nodes) {
|
for (auto node : nodes) {
|
||||||
m_ast = node;
|
m_ast = node;
|
||||||
m_env = env;
|
m_env = env;
|
||||||
|
|||||||
Reference in New Issue
Block a user