From 4047c6811d2d4532ca39e0b716257df63cecf86d Mon Sep 17 00:00:00 2001 From: VaclavT Date: Tue, 9 Feb 2021 17:44:38 +0100 Subject: [PATCH] a few more consts --- ml.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ml.cpp b/ml.cpp index bfaf636..6762f13 100644 --- a/ml.cpp +++ b/ml.cpp @@ -152,7 +152,7 @@ class Error { public: // Create an error with the value that caused the error, // the scope where the error was found, and the message. - Error(Value v, Environment const &env, const char *msg); + Error(const Value &v, Environment const &env, const char *msg); // Copy constructor is needed to prevent double frees Error(Error const &other); ~Error(); @@ -183,7 +183,7 @@ public: // Constructs a floating point value Value(double f) : type(FLOAT) { stack_data.f = f; } // Constructs a list - Value(std::vector list) : type(LIST), list(list) {} + Value(const std::vector &list) : type(LIST), list(list) {} // Construct a quoted value static Value quote(Value quoted) { @@ -197,7 +197,7 @@ public: } // Construct an atom - static Value atom(std::string s) { + static Value atom(const std::string &s) { Value result; result.type = ATOM; @@ -207,7 +207,7 @@ public: } // Construct a string - static Value string(std::string s) { + static Value string(const std::string &s) { Value result; result.type = STRING; @@ -217,7 +217,7 @@ public: } // Construct a lambda function - Value(std::vector params, Value ret, Environment const &env) : type(LAMBDA) { + Value(const std::vector ¶ms, Value ret, Environment const &env) : type(LAMBDA) { // We store the params and the result in the list member // instead of having dedicated members. This is to save memory. list.push_back(Value(params)); @@ -233,7 +233,7 @@ public: } // Construct a builtin function - Value(std::string name, Builtin b) : type(BUILTIN) { + Value(const std::string &name, Builtin b) : type(BUILTIN) { // Store the name of the builtin function in the str member // to save memory, and use the builtin function slot in the union // to store the function pointer. @@ -773,7 +773,7 @@ private: Environment lambda_scope; }; -Error::Error(Value v, Environment const &env, const char *msg) : env(env), msg(msg) { +Error::Error(const Value &v, Environment const &env, const char *msg) : env(env), msg(msg) { cause = new Value; *cause = v; } @@ -1014,7 +1014,7 @@ std::vector parse(std::string s) { } // Execute code in an environment -Value run(std::string code, Environment &env) { +Value run(const std::string &code, Environment &env) { // Parse the code std::vector parsed = parse(code); // Iterate over the expressions and evaluate them