fix: dynamic counting for modulo arg counts
This commit is contained in:
parent
4a02f7cb95
commit
282071efc1
2 changed files with 8 additions and 3 deletions
|
@ -107,9 +107,7 @@ pub fn core_environment() -> Rc<Environment> {
|
|||
(
|
||||
"hashmap",
|
||||
Expression::NativeFunc(|args| {
|
||||
if args.len() % 2 != 0 {
|
||||
Err(Error::MismatchedArgCount(2, args.len()))?
|
||||
}
|
||||
arg_count!(modulo: 2, args.len());
|
||||
|
||||
let mut index = -1;
|
||||
let (keys, values): (Vec<_>, Vec<_>) = args.into_iter().partition(|_| {
|
||||
|
|
|
@ -5,6 +5,13 @@ macro_rules! arg_count {
|
|||
Err(Error::MismatchedArgCount($expected, $given))?
|
||||
}
|
||||
};
|
||||
|
||||
(modulo: $modulo:expr, $given:expr) => {
|
||||
Err(Error::MismatchedArgCount(
|
||||
($given / $modulo) * $modulo + $modulo,
|
||||
$given,
|
||||
))?
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use arg_count;
|
||||
|
|
Loading…
Reference in a new issue