Name refactoring.

This commit is contained in:
yhirose 2015-06-03 18:42:25 -04:00
parent 471ed98277
commit 97235c313b
2 changed files with 7 additions and 5 deletions

View File

@ -103,13 +103,13 @@ private:
if (fv.params.size() <= args.size()) { if (fv.params.size() <= args.size()) {
auto callEnv = make_shared<Environment>(); auto callEnv = make_shared<Environment>();
callEnv->declare("self", f, false); callEnv->initialize("self", f, false);
for (auto i = 0u; i < fv.params.size(); i++) { for (auto i = 0u; i < fv.params.size(); i++) {
auto param = fv.params[i]; auto param = fv.params[i];
auto arg = args[i]; auto arg = args[i];
auto val = eval(*arg, env); auto val = eval(*arg, env);
callEnv->declare(param.name, val, param.mut); callEnv->initialize(param.name, val, param.mut);
} }
return fv.eval(callEnv); return fv.eval(callEnv);
@ -167,7 +167,7 @@ private:
if (env->has(var)) { if (env->has(var)) {
env->assign(var, val); env->assign(var, val);
} else { } else {
env->declare(var, val, mut == "mut"); env->initialize(var, val, mut == "mut");
} }
return val; return val;
}; };

View File

@ -217,15 +217,17 @@ struct Environment
outer_->assign(s, val); outer_->assign(s, val);
return; return;
} }
// NOTREACHED
throw std::logic_error("invalid internal condition.");
} }
void declare(const std::string& s, const Value& val, bool mut) { void initialize(const std::string& s, const Value& val, bool mut) {
assert(!has(s)); assert(!has(s));
dic_[s] = Symbol{val, mut}; dic_[s] = Symbol{val, mut};
} }
void setup_built_in_functions() { void setup_built_in_functions() {
declare( initialize(
"pp", "pp",
Value(Value::FunctionValue { Value(Value::FunctionValue {
{ {"arg", true} }, { {"arg", true} },