Blocks can accept now more parameters then they capture
This commit is contained in:
parent
b924f7dff2
commit
fe6c1e3bd0
12
CHANGELOG.md
12
CHANGELOG.md
@ -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/),
|
||||
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
|
||||
|
||||
### Added
|
||||
|
@ -36,7 +36,7 @@ Result<Value> Block::operator()(Interpreter &i, std::vector<Value> arguments) co
|
||||
auto old_scope = std::exchange(i.env, context);
|
||||
i.enter_scope();
|
||||
|
||||
if (parameters.size() != arguments.size()) {
|
||||
if (parameters.size() > arguments.size()) {
|
||||
return errors::Wrong_Arity_Of {
|
||||
.type = errors::Wrong_Arity_Of::Function,
|
||||
// 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]));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user