define renamed to def, defun renamed to defn
This commit is contained in:
12
ml.cpp
12
ml.cpp
@@ -977,7 +977,7 @@ MlValue cond(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
// Define a variable with a value (SPECIAL FORM)
|
||||
MlValue define(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
if (args.size() != 2)
|
||||
throw MlError(MlValue("define", define), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||
throw MlError(MlValue("def", define), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||
|
||||
MlValue result = args[1].eval(env);
|
||||
env.set(args[0].display(), result);
|
||||
@@ -987,10 +987,10 @@ MlValue define(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
// Define a function with parameters and a result expression (SPECIAL FORM)
|
||||
MlValue defun(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
if (args.size() != 3)
|
||||
throw MlError(MlValue("defun", defun), env, args.size() > 3 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||
throw MlError(MlValue("defn", defun), env, args.size() > 3 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||
|
||||
if (args[1].get_type_name() != LIST_TYPE)
|
||||
throw MlError(MlValue("defun", defun), env, INVALID_LAMBDA);
|
||||
throw MlError(MlValue("defn", defun), env, INVALID_LAMBDA);
|
||||
|
||||
MlValue f = MlValue(args[1].as_list(), args[2], env);
|
||||
env.set(args[0].display(), f);
|
||||
@@ -2100,7 +2100,7 @@ bool MlEnvironment::has(const std::string &name) const {
|
||||
std::map <const std::string, Builtin> builtin_funcs
|
||||
{
|
||||
// Special forms
|
||||
std::make_pair("define", builtin::define),
|
||||
std::make_pair("def", builtin::define),
|
||||
std::make_pair("lambda", builtin::lambda),
|
||||
std::make_pair("if", builtin::if_then_else),
|
||||
std::make_pair("cond", builtin::cond),
|
||||
@@ -2109,7 +2109,7 @@ std::map <const std::string, Builtin> builtin_funcs
|
||||
std::make_pair("while", builtin::while_loop),
|
||||
std::make_pair("scope", builtin::scope),
|
||||
std::make_pair("quote", builtin::quote),
|
||||
std::make_pair("defun", builtin::defun),
|
||||
std::make_pair("defn", builtin::defun),
|
||||
std::make_pair("and", builtin::do_and),
|
||||
std::make_pair("or", builtin::do_or),
|
||||
std::make_pair("set!", builtin::setx),
|
||||
@@ -2225,7 +2225,7 @@ std::map <const std::string, Builtin> builtin_funcs
|
||||
// Get the value associated with this name in this scope
|
||||
MlValue MlEnvironment::get(const std::string &name) const {
|
||||
// PERF, here can be a few of for fast access
|
||||
if (name == "define") return MlValue("define", builtin::define);
|
||||
if (name == "defe") return MlValue("def", builtin::define);
|
||||
if (name == "if") return MlValue("if", builtin::if_then_else);
|
||||
if (name == "lambda") return MlValue("lambda", builtin::lambda);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user