handling nil fix

This commit is contained in:
vaclavt 2022-01-22 23:03:13 +01:00
parent ea09216550
commit d72b758c59
2 changed files with 2 additions and 3 deletions

4
ml.cpp
View File

@ -197,7 +197,7 @@ bool MlValue::is_list() const {
} }
bool MlValue::as_bool() const { bool MlValue::as_bool() const {
return type != NIL; return !(type == NIL || (type == LIST && list.empty()));
} }
long MlValue::as_int() const { long MlValue::as_int() const {
@ -949,7 +949,7 @@ MlValue if_then_else(std::vector<MlValue> args, MlEnvironment &env) {
else if (args.size() == 3) else if (args.size() == 3)
return args[2].eval(env); return args[2].eval(env);
return MlValue(0l); return MlValue::nil();
} }
// cond (SPECIAL FORM), in lisp it's macro, but we don't have support for macros yet // cond (SPECIAL FORM), in lisp it's macro, but we don't have support for macros yet

View File

@ -30,7 +30,6 @@ bool regexp_search(const std::string &where, const std::string &regex_str) {
// for (size_t i = 0; i < match.size(); ++i) // for (size_t i = 0; i < match.size(); ++i)
// std::cout << i << ": " << match[i] << '\n'; // std::cout << i << ": " << match[i] << '\n';
// std::cout << "Suffix: '" << match.suffix() << "\'\n\n"; // std::cout << "Suffix: '" << match.suffix() << "\'\n\n";
return true; return true;
} }
return false; return false;