From 8aa540c4e50f8bc50619c32e69dc55f3347b70c2 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Mon, 17 Apr 2023 14:14:55 +0200 Subject: [PATCH] Env: Core function (get) should work on nil value --- src/functions.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/functions.cpp b/src/functions.cpp index ee7fe5e..b467127 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -662,6 +662,7 @@ ADD_FUNCTION( return result; }); +// (assoc {:a 1 :b 2} :a 3 :c 1) ADD_FUNCTION( "assoc", { @@ -698,11 +699,17 @@ ADD_FUNCTION( return result; }); +// (get {:kw "value"} :kw) ADD_FUNCTION( "get", { CHECK_ARG_COUNT_AT_LEAST("get", nodes.size(), 1); + if (is(nodes.front().get()) + && std::static_pointer_cast(nodes.front())->state() == Constant::Nil) { + return makePtr(); + } + VALUE_CAST(hash_map, HashMap, nodes.front()); nodes.pop_front();