|
|
@ -166,21 +166,15 @@ ASTNodePtr Eval::evalLet(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env) |
|
|
|
auto second_argument = *std::next(nodes.begin()); |
|
|
|
auto second_argument = *std::next(nodes.begin()); |
|
|
|
|
|
|
|
|
|
|
|
// First argument needs to be a List or Vector
|
|
|
|
// First argument needs to be a List or Vector
|
|
|
|
if (!is<List>(first_argument.get()) && !is<Vector>(first_argument.get())) { |
|
|
|
if (!is<Collection>(first_argument.get())) { |
|
|
|
Error::the().addError(format("wrong argument type: list, '{}'", first_argument)); |
|
|
|
Error::the().addError(format("wrong argument type: collection, '{}'", first_argument)); |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get the nodes out of the List or Vector
|
|
|
|
// Get the nodes out of the List or Vector
|
|
|
|
std::list<ASTNodePtr> binding_nodes; |
|
|
|
std::list<ASTNodePtr> binding_nodes; |
|
|
|
if (is<List>(first_argument.get())) { |
|
|
|
auto bindings = std::static_pointer_cast<Collection>(first_argument); |
|
|
|
auto bindings = std::static_pointer_cast<List>(first_argument); |
|
|
|
|
|
|
|
binding_nodes = bindings->nodes(); |
|
|
|
binding_nodes = bindings->nodes(); |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
auto bindings = std::static_pointer_cast<Vector>(first_argument); |
|
|
|
|
|
|
|
binding_nodes = bindings->nodes(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// List or Vector needs to have an even number of elements
|
|
|
|
// List or Vector needs to have an even number of elements
|
|
|
|
size_t count = binding_nodes.size(); |
|
|
|
size_t count = binding_nodes.size(); |
|
|
@ -269,11 +263,11 @@ ASTNodePtr Eval::evalFn(const std::list<ASTNodePtr>& nodes, EnvironmentPtr env) |
|
|
|
auto first_argument = *nodes.begin(); |
|
|
|
auto first_argument = *nodes.begin(); |
|
|
|
auto second_argument = *std::next(nodes.begin()); |
|
|
|
auto second_argument = *std::next(nodes.begin()); |
|
|
|
|
|
|
|
|
|
|
|
// First element needs to be a List
|
|
|
|
// First element needs to be a List or Vector
|
|
|
|
AST_CAST(List, first_argument, list); |
|
|
|
AST_CAST(Collection, first_argument, collection); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> bindings; |
|
|
|
std::vector<std::string> bindings; |
|
|
|
for (auto node : list->nodes()) { |
|
|
|
for (auto node : collection->nodes()) { |
|
|
|
// All nodes need to be a Symbol
|
|
|
|
// All nodes need to be a Symbol
|
|
|
|
AST_CAST(Symbol, node, symbol); |
|
|
|
AST_CAST(Symbol, node, symbol); |
|
|
|
bindings.push_back(symbol->symbol()); |
|
|
|
bindings.push_back(symbol->symbol()); |
|
|
|