From 6638cdff553d1a91174b051b5b37c776d4db4158 Mon Sep 17 00:00:00 2001 From: VaclavT Date: Mon, 19 Apr 2021 21:17:10 +0200 Subject: [PATCH] set! functionality fix this will be probably changed in future --- ml.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ml.cpp b/ml.cpp index 7b5d6b4..490d782 100644 --- a/ml.cpp +++ b/ml.cpp @@ -110,13 +110,13 @@ MlValue::MlValue(const std::vector ¶ms, MlValue ret, MlEnvironment list.push_back(MlValue(params)); list.push_back(ret); - // Lambdas capture only variables that they know they will use. - std::vector used_atoms = ret.get_used_atoms(); - for (size_t i = 0; i < used_atoms.size(); i++) { - // If the environment has a symbol that this lambda uses, capture it. - if (env.has(used_atoms[i])) - lambda_scope.set(used_atoms[i], env.get(used_atoms[i])); - } +// // Lambdas capture only variables that they know they will use. +// std::vector used_atoms = ret.get_used_atoms(); +// for (size_t i = 0; i < used_atoms.size(); i++) { +// // If the environment has a symbol that this lambda uses, capture it. +// if (env.has(used_atoms[i])) +// lambda_scope.set(used_atoms[i], env.get(used_atoms[i])); +// } } // Construct a builtin function @@ -653,16 +653,15 @@ void MlEnvironment::set(const std::string &name, MlValue value) { void MlEnvironment::setX(const std::string &name, MlValue value) { - MlEnvironment* e = this; - do { + MlEnvironment* e = this->parent_scope; // we start above this scope for set! + while (e != nullptr) { std::map::const_iterator itr = e->defs.find(name); if (itr != e->defs.end()) { e->set(name, value); return; } e = e->parent_scope; - } while (e != nullptr); - + } // not found so define this->set(name, value); }