From 358414d7d3901fff9673f4f414b13a8c750b240d Mon Sep 17 00:00:00 2001 From: VaclavT Date: Tue, 4 May 2021 19:59:49 +0200 Subject: [PATCH] do not suppose in eval that list first element is function --- ml.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ml.cpp b/ml.cpp index 0489169..563488a 100644 --- a/ml.cpp +++ b/ml.cpp @@ -729,20 +729,20 @@ MlValue MlValue::eval(MlEnvironment &env) { args = std::vector(list.begin() + 1, list.end()); - // Only evaluate our arguments if it's not builtin! - // Builtin functions can be special forms, so we - // leave them to evaluate their arguments. function = list[0].eval(env); + if (function.type == BUILTIN || function.type == LAMBDA) { + // Only evaluate our arguments if it's not builtin! + // Builtin functions can be special forms, so we + // leave them to evaluate their arguments. + if (!function.is_builtin()) + for (size_t i = 0; i < args.size(); i++) + args[i] = args[i].eval(env); - if (!function.is_builtin()) - for (size_t i = 0; i < args.size(); i++) - args[i] = args[i].eval(env); - - MlPerfMon::instance().add_method_call(function.type == LAMBDA ? "lambda" : function.str); - res = function.apply( args, env ); - MlPerfMon::instance().end_method_call(); - - return res; + MlPerfMon::instance().add_method_call(function.type == LAMBDA ? "lambda" : function.str); + res = function.apply(args, env); + MlPerfMon::instance().end_method_call(); + return res; + } default: return *this;