Blocks can accept now more parameters then they capture

This commit is contained in:
Robert Bendun 2022-10-23 12:24:32 +02:00
parent b924f7dff2
commit fe6c1e3bd0
2 changed files with 14 additions and 2 deletions

View File

@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- Block can be called with more parameters then it requires
## [0.2.1] - 2022-10-21
### Fixed
- Windows build doesn't require pthread dll
## [0.2.0] - 2022-10-21 ## [0.2.0] - 2022-10-21
### Added ### Added

View File

@ -36,7 +36,7 @@ Result<Value> Block::operator()(Interpreter &i, std::vector<Value> arguments) co
auto old_scope = std::exchange(i.env, context); auto old_scope = std::exchange(i.env, context);
i.enter_scope(); i.enter_scope();
if (parameters.size() != arguments.size()) { if (parameters.size() > arguments.size()) {
return errors::Wrong_Arity_Of { return errors::Wrong_Arity_Of {
.type = errors::Wrong_Arity_Of::Function, .type = errors::Wrong_Arity_Of::Function,
// TODO Let user defined functions have name of their first assigment (Zig like) // TODO Let user defined functions have name of their first assigment (Zig like)
@ -47,7 +47,7 @@ Result<Value> Block::operator()(Interpreter &i, std::vector<Value> arguments) co
}; };
} }
for (usize j = 0; j < parameters.size(); ++j) { for (usize j = 0; j < std::min(parameters.size(), arguments.size()); ++j) {
i.env->force_define(parameters[j], std::move(arguments[j])); i.env->force_define(parameters[j], std::move(arguments[j]));
} }