Browse Source

Env: Core function (get) should work on nil value

master
Riyyi 2 years ago
parent
commit
8aa540c4e5
  1. 7
      src/functions.cpp

7
src/functions.cpp

@ -662,6 +662,7 @@ ADD_FUNCTION(
return result; return result;
}); });
// (assoc {:a 1 :b 2} :a 3 :c 1)
ADD_FUNCTION( ADD_FUNCTION(
"assoc", "assoc",
{ {
@ -698,11 +699,17 @@ ADD_FUNCTION(
return result; return result;
}); });
// (get {:kw "value"} :kw)
ADD_FUNCTION( ADD_FUNCTION(
"get", "get",
{ {
CHECK_ARG_COUNT_AT_LEAST("get", nodes.size(), 1); CHECK_ARG_COUNT_AT_LEAST("get", nodes.size(), 1);
if (is<Constant>(nodes.front().get())
&& std::static_pointer_cast<Constant>(nodes.front())->state() == Constant::Nil) {
return makePtr<Constant>();
}
VALUE_CAST(hash_map, HashMap, nodes.front()); VALUE_CAST(hash_map, HashMap, nodes.front());
nodes.pop_front(); nodes.pop_front();

Loading…
Cancel
Save