|
|
@ -16,250 +16,253 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace blaze { |
|
|
|
namespace blaze { |
|
|
|
|
|
|
|
|
|
|
|
// (apply + 1 2 (list 3 4)) -> (+ 1 2 3 4) -> 10
|
|
|
|
void Environment::loadCollectionModify() |
|
|
|
ADD_FUNCTION( |
|
|
|
{ |
|
|
|
"apply", |
|
|
|
// (apply + 1 2 (list 3 4)) -> (+ 1 2 3 4) -> 10
|
|
|
|
{ |
|
|
|
ADD_FUNCTION( |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("apply", SIZE(), 2); |
|
|
|
"apply", |
|
|
|
|
|
|
|
{ |
|
|
|
auto callable = *begin; |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("apply", SIZE(), 2); |
|
|
|
IS_VALUE(Callable, callable); |
|
|
|
|
|
|
|
|
|
|
|
auto callable = *begin; |
|
|
|
VALUE_CAST(collection, Collection, (*std::prev(end))); |
|
|
|
IS_VALUE(Callable, callable); |
|
|
|
|
|
|
|
|
|
|
|
auto arguments = ValueVector(begin + 1, end - 1); |
|
|
|
VALUE_CAST(collection, Collection, (*std::prev(end))); |
|
|
|
arguments.reserve(arguments.size() + collection->size()); |
|
|
|
|
|
|
|
|
|
|
|
auto arguments = ValueVector(begin + 1, end - 1); |
|
|
|
// Append list nodes to the argument leftovers
|
|
|
|
arguments.reserve(arguments.size() + collection->size()); |
|
|
|
auto nodes = collection->nodesRead(); |
|
|
|
|
|
|
|
for (const auto& node : nodes) { |
|
|
|
// Append list nodes to the argument leftovers
|
|
|
|
arguments.push_back(node); |
|
|
|
auto nodes = collection->nodesRead(); |
|
|
|
} |
|
|
|
for (const auto& node : nodes) { |
|
|
|
|
|
|
|
arguments.push_back(node); |
|
|
|
ValuePtr value = nullptr; |
|
|
|
} |
|
|
|
if (is<Function>(callable.get())) { |
|
|
|
|
|
|
|
auto function = std::static_pointer_cast<Function>(callable)->function(); |
|
|
|
|
|
|
|
value = function(arguments.begin(), arguments.end()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
auto lambda = std::static_pointer_cast<Lambda>(callable); |
|
|
|
|
|
|
|
value = eval(lambda->body(), Environment::create(lambda, std::move(arguments))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return value; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// (cons 1 (list 2 3))
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"cons", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_IS("cons", SIZE(), 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ValuePtr first = *begin; |
|
|
|
|
|
|
|
begin++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(collection, Collection, (*begin)); |
|
|
|
|
|
|
|
const auto& collection_nodes = collection->nodesRead(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto result_nodes = ValueVector(collection_nodes.size() + 1); |
|
|
|
|
|
|
|
result_nodes.at(0) = first; |
|
|
|
|
|
|
|
std::copy(collection_nodes.begin(), collection_nodes.end(), result_nodes.begin() + 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// (concat (list 1) (list 2 3)) -> (1 2 3)
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"concat", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
size_t count = 0; |
|
|
|
|
|
|
|
for (auto it = begin; it != end; ++it) { |
|
|
|
|
|
|
|
VALUE_CAST(collection, Collection, (*it)); |
|
|
|
|
|
|
|
count += collection->size(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto result_nodes = ValueVector(count); |
|
|
|
|
|
|
|
size_t offset = 0; |
|
|
|
|
|
|
|
for (auto it = begin; it != end; ++it) { |
|
|
|
|
|
|
|
const auto& collection_nodes = std::static_pointer_cast<Collection>(*it)->nodesRead(); |
|
|
|
|
|
|
|
std::copy(collection_nodes.begin(), collection_nodes.end(), result_nodes.begin() + offset); |
|
|
|
|
|
|
|
offset += collection_nodes.size(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// (conj '(1 2 3) 4 5 6) -> (6 5 4 1 2 3)
|
|
|
|
|
|
|
|
// (conj [1 2 3] 4 5 6) -> [1 2 3 4 5 6]
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"conj", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_AT_LEAST("conj", SIZE(), 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(collection, Collection, (*begin)); |
|
|
|
|
|
|
|
begin++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto& collection_nodes = collection->nodesRead(); |
|
|
|
|
|
|
|
size_t collection_count = collection_nodes.size(); |
|
|
|
|
|
|
|
size_t argument_count = SIZE(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto nodes = ValueVector(argument_count + collection_count); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is<List>(collection.get())) { |
|
|
|
|
|
|
|
std::reverse_copy(begin, end, nodes.begin()); |
|
|
|
|
|
|
|
std::copy(collection_nodes.begin(), collection_nodes.end(), nodes.begin() + argument_count); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(nodes); |
|
|
|
ValuePtr value = nullptr; |
|
|
|
} |
|
|
|
if (is<Function>(callable.get())) { |
|
|
|
|
|
|
|
auto function = std::static_pointer_cast<Function>(callable)->function(); |
|
|
|
|
|
|
|
value = function(arguments.begin(), arguments.end()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
auto lambda = std::static_pointer_cast<Lambda>(callable); |
|
|
|
|
|
|
|
value = eval(lambda->body(), Environment::create(lambda, std::move(arguments))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::copy(collection_nodes.begin(), collection_nodes.end(), nodes.begin()); |
|
|
|
return value; |
|
|
|
std::copy(begin, end, nodes.begin() + collection_count); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<Vector>(nodes); |
|
|
|
// (cons 1 (list 2 3))
|
|
|
|
}); |
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"cons", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_IS("cons", SIZE(), 2); |
|
|
|
|
|
|
|
|
|
|
|
// (map (fn* (x) (* x 2)) (list 1 2 3)) -> (2 4 6)
|
|
|
|
ValuePtr first = *begin; |
|
|
|
ADD_FUNCTION( |
|
|
|
begin++; |
|
|
|
"map", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_IS("map", SIZE(), 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(callable, Callable, (*begin)); |
|
|
|
VALUE_CAST(collection, Collection, (*begin)); |
|
|
|
VALUE_CAST(collection, Collection, (*(begin + 1))); |
|
|
|
const auto& collection_nodes = collection->nodesRead(); |
|
|
|
|
|
|
|
|
|
|
|
size_t count = collection->size(); |
|
|
|
auto result_nodes = ValueVector(collection_nodes.size() + 1); |
|
|
|
auto nodes = ValueVector(count); |
|
|
|
result_nodes.at(0) = first; |
|
|
|
|
|
|
|
std::copy(collection_nodes.begin(), collection_nodes.end(), result_nodes.begin() + 1); |
|
|
|
|
|
|
|
|
|
|
|
if (is<Function>(callable.get())) { |
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
auto function = std::static_pointer_cast<Function>(callable)->function(); |
|
|
|
}); |
|
|
|
for (size_t i = 0; i < count; ++i) { |
|
|
|
|
|
|
|
nodes.at(i) = function(collection->begin() + i, collection->begin() + i + 1); |
|
|
|
// (concat (list 1) (list 2 3)) -> (1 2 3)
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"concat", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
size_t count = 0; |
|
|
|
|
|
|
|
for (auto it = begin; it != end; ++it) { |
|
|
|
|
|
|
|
VALUE_CAST(collection, Collection, (*it)); |
|
|
|
|
|
|
|
count += collection->size(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
auto result_nodes = ValueVector(count); |
|
|
|
auto lambda = std::static_pointer_cast<Lambda>(callable); |
|
|
|
size_t offset = 0; |
|
|
|
auto collection_nodes = collection->nodesRead(); |
|
|
|
for (auto it = begin; it != end; ++it) { |
|
|
|
for (size_t i = 0; i < count; ++i) { |
|
|
|
const auto& collection_nodes = std::static_pointer_cast<Collection>(*it)->nodesRead(); |
|
|
|
nodes.at(i) = (eval(lambda->body(), Environment::create(lambda, { collection_nodes[i] }))); |
|
|
|
std::copy(collection_nodes.begin(), collection_nodes.end(), result_nodes.begin() + offset); |
|
|
|
|
|
|
|
offset += collection_nodes.size(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(nodes); |
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (set-nth (list 1 2 3) 1 "foo") -> (1 "foo" 3)
|
|
|
|
// (conj '(1 2 3) 4 5 6) -> (6 5 4 1 2 3)
|
|
|
|
ADD_FUNCTION( |
|
|
|
// (conj [1 2 3] 4 5 6) -> [1 2 3 4 5 6]
|
|
|
|
"set-nth", |
|
|
|
ADD_FUNCTION( |
|
|
|
{ |
|
|
|
"conj", |
|
|
|
CHECK_ARG_COUNT_IS("set-nth-element", SIZE(), 3); |
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_AT_LEAST("conj", SIZE(), 1); |
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(collection, Collection, (*begin)); |
|
|
|
VALUE_CAST(collection, Collection, (*begin)); |
|
|
|
|
|
|
|
begin++; |
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(number_node, Number, (*(begin + 1))); |
|
|
|
const auto& collection_nodes = collection->nodesRead(); |
|
|
|
auto index = static_cast<size_t>(number_node->number() < 0 ? 0 : number_node->number()); |
|
|
|
size_t collection_count = collection_nodes.size(); |
|
|
|
|
|
|
|
size_t argument_count = SIZE(); |
|
|
|
|
|
|
|
|
|
|
|
auto value = *(begin + 2); |
|
|
|
auto nodes = ValueVector(argument_count + collection_count); |
|
|
|
|
|
|
|
|
|
|
|
auto collection_nodes = collection->nodesCopy(); |
|
|
|
if (is<List>(collection.get())) { |
|
|
|
if (index >= collection->size()) { // Enlarge list if index out of bounds
|
|
|
|
std::reverse_copy(begin, end, nodes.begin()); |
|
|
|
collection_nodes.resize(index + 1, makePtr<Constant>()); |
|
|
|
std::copy(collection_nodes.begin(), collection_nodes.end(), nodes.begin() + argument_count); |
|
|
|
} |
|
|
|
|
|
|
|
collection_nodes[index] = value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is<Vector>(begin->get())) { |
|
|
|
return makePtr<List>(nodes); |
|
|
|
return makePtr<Vector>(collection_nodes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(collection_nodes); |
|
|
|
std::copy(collection_nodes.begin(), collection_nodes.end(), nodes.begin()); |
|
|
|
}); |
|
|
|
std::copy(begin, end, nodes.begin() + collection_count); |
|
|
|
|
|
|
|
|
|
|
|
// (seq '(1 2 3)) -> (1 2 3)
|
|
|
|
return makePtr<Vector>(nodes); |
|
|
|
// (seq [1 2 3]) -> (1 2 3)
|
|
|
|
}); |
|
|
|
// (seq "foo") -> ("f" "o" "o")
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"seq", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_IS("seq", SIZE(), 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto front = *begin; |
|
|
|
// (map (fn* (x) (* x 2)) (list 1 2 3)) -> (2 4 6)
|
|
|
|
Value* front_raw_ptr = front.get(); |
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"map", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_IS("map", SIZE(), 2); |
|
|
|
|
|
|
|
|
|
|
|
if (is<Constant>(front_raw_ptr) && std::static_pointer_cast<Constant>(front)->state() == Constant::Nil) { |
|
|
|
VALUE_CAST(callable, Callable, (*begin)); |
|
|
|
return makePtr<Constant>(); |
|
|
|
VALUE_CAST(collection, Collection, (*(begin + 1))); |
|
|
|
} |
|
|
|
|
|
|
|
if (is<Collection>(front_raw_ptr)) { |
|
|
|
|
|
|
|
auto collection = std::static_pointer_cast<Collection>(front); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (collection->empty()) { |
|
|
|
size_t count = collection->size(); |
|
|
|
return makePtr<Constant>(); |
|
|
|
auto nodes = ValueVector(count); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is<Function>(callable.get())) { |
|
|
|
|
|
|
|
auto function = std::static_pointer_cast<Function>(callable)->function(); |
|
|
|
|
|
|
|
for (size_t i = 0; i < count; ++i) { |
|
|
|
|
|
|
|
nodes.at(i) = function(collection->begin() + i, collection->begin() + i + 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
auto lambda = std::static_pointer_cast<Lambda>(callable); |
|
|
|
|
|
|
|
auto collection_nodes = collection->nodesRead(); |
|
|
|
|
|
|
|
for (size_t i = 0; i < count; ++i) { |
|
|
|
|
|
|
|
nodes.at(i) = (eval(lambda->body(), Environment::create(lambda, { collection_nodes[i] }))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(nodes); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// (set-nth (list 1 2 3) 1 "foo") -> (1 "foo" 3)
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"set-nth", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_IS("set-nth-element", SIZE(), 3); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(collection, Collection, (*begin)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(number_node, Number, (*(begin + 1))); |
|
|
|
|
|
|
|
auto index = static_cast<size_t>(number_node->number() < 0 ? 0 : number_node->number()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto value = *(begin + 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto collection_nodes = collection->nodesCopy(); |
|
|
|
|
|
|
|
if (index >= collection->size()) { // Enlarge list if index out of bounds
|
|
|
|
|
|
|
|
collection_nodes.resize(index + 1, makePtr<Constant>()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
collection_nodes[index] = value; |
|
|
|
|
|
|
|
|
|
|
|
if (is<List>(front_raw_ptr)) { |
|
|
|
if (is<Vector>(begin->get())) { |
|
|
|
return front; |
|
|
|
return makePtr<Vector>(collection_nodes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(collection->nodesCopy()); |
|
|
|
return makePtr<List>(collection_nodes); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (is<String>(front_raw_ptr)) { |
|
|
|
|
|
|
|
auto string = std::static_pointer_cast<String>(front); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string->empty()) { |
|
|
|
// (seq '(1 2 3)) -> (1 2 3)
|
|
|
|
|
|
|
|
// (seq [1 2 3]) -> (1 2 3)
|
|
|
|
|
|
|
|
// (seq "foo") -> ("f" "o" "o")
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"seq", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_IS("seq", SIZE(), 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto front = *begin; |
|
|
|
|
|
|
|
Value* front_raw_ptr = front.get(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is<Constant>(front_raw_ptr) && std::static_pointer_cast<Constant>(front)->state() == Constant::Nil) { |
|
|
|
return makePtr<Constant>(); |
|
|
|
return makePtr<Constant>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (is<Collection>(front_raw_ptr)) { |
|
|
|
|
|
|
|
auto collection = std::static_pointer_cast<Collection>(front); |
|
|
|
|
|
|
|
|
|
|
|
size_t count = string->size(); |
|
|
|
if (collection->empty()) { |
|
|
|
auto nodes = ValueVector(count); |
|
|
|
return makePtr<Constant>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is<List>(front_raw_ptr)) { |
|
|
|
|
|
|
|
return front; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const auto& data = string->data(); |
|
|
|
return makePtr<List>(collection->nodesCopy()); |
|
|
|
for (size_t i = 0; i < count; ++i) { |
|
|
|
|
|
|
|
nodes.at(i) = makePtr<String>(data[i]); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (is<String>(front_raw_ptr)) { |
|
|
|
|
|
|
|
auto string = std::static_pointer_cast<String>(front); |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<List>(nodes); |
|
|
|
if (string->empty()) { |
|
|
|
} |
|
|
|
return makePtr<Constant>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t count = string->size(); |
|
|
|
|
|
|
|
auto nodes = ValueVector(count); |
|
|
|
|
|
|
|
|
|
|
|
Error::the().add(::format("wrong argument type: Collection or String, {}", front)); |
|
|
|
const auto& data = string->data(); |
|
|
|
|
|
|
|
for (size_t i = 0; i < count; ++i) { |
|
|
|
|
|
|
|
nodes.at(i) = makePtr<String>(data[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nullptr; |
|
|
|
return makePtr<List>(nodes); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
Error::the().add(::format("wrong argument type: Collection or String, {}", front)); |
|
|
|
|
|
|
|
|
|
|
|
// (assoc {:a 1 :b 2} :a 3 :c 1) -> {:a 3 :b 2 :c 1}
|
|
|
|
return nullptr; |
|
|
|
ADD_FUNCTION( |
|
|
|
}); |
|
|
|
"assoc", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_AT_LEAST("assoc", SIZE(), 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(hash_map, HashMap, (*begin)); |
|
|
|
// -----------------------------------------
|
|
|
|
begin++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CHECK_ARG_COUNT_EVEN("assoc", SIZE()); |
|
|
|
// (assoc {:a 1 :b 2} :a 3 :c 1) -> {:a 3 :b 2 :c 1}
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
|
|
|
|
"assoc", |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_AT_LEAST("assoc", SIZE(), 1); |
|
|
|
|
|
|
|
|
|
|
|
Elements elements(hash_map->elements()); |
|
|
|
VALUE_CAST(hash_map, HashMap, (*begin)); |
|
|
|
for (auto it = begin; it != end; std::advance(it, 2)) { |
|
|
|
begin++; |
|
|
|
const ValuePtr& value = *(std::next(it)); // temporary instance to get around const
|
|
|
|
|
|
|
|
elements.insert_or_assign(HashMap::getKeyString(*it), value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return makePtr<HashMap>(elements); |
|
|
|
CHECK_ARG_COUNT_EVEN("assoc", SIZE()); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// (dissoc {:a 1 :b 2 :c 3} :a :c :d) -> {:b 2}
|
|
|
|
Elements elements(hash_map->elements()); |
|
|
|
ADD_FUNCTION( |
|
|
|
for (auto it = begin; it != end; std::advance(it, 2)) { |
|
|
|
"dissoc", |
|
|
|
const ValuePtr& value = *(std::next(it)); // temporary instance to get around const
|
|
|
|
{ |
|
|
|
elements.insert_or_assign(HashMap::getKeyString(*it), value); |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("dissoc", SIZE(), 1); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(hash_map, HashMap, (*begin)); |
|
|
|
return makePtr<HashMap>(elements); |
|
|
|
begin++; |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Elements elements(hash_map->elements()); |
|
|
|
// (dissoc {:a 1 :b 2 :c 3} :a :c :d) -> {:b 2}
|
|
|
|
for (auto it = begin; it != end; ++it) { |
|
|
|
ADD_FUNCTION( |
|
|
|
elements.erase(HashMap::getKeyString(*it)); |
|
|
|
"dissoc", |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
CHECK_ARG_COUNT_AT_LEAST("dissoc", SIZE(), 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VALUE_CAST(hash_map, HashMap, (*begin)); |
|
|
|
|
|
|
|
begin++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Elements elements(hash_map->elements()); |
|
|
|
|
|
|
|
for (auto it = begin; it != end; ++it) { |
|
|
|
|
|
|
|
elements.erase(HashMap::getKeyString(*it)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<HashMap>(elements); |
|
|
|
return makePtr<HashMap>(elements); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace blaze
|
|
|
|
} // namespace blaze
|
|
|
|