fix: dynamic counting for modulo arg counts

This commit is contained in:
Roman Godmaire 2024-02-17 22:36:01 -05:00
parent 4a02f7cb95
commit 282071efc1
2 changed files with 8 additions and 3 deletions

View file

@ -107,9 +107,7 @@ pub fn core_environment() -> Rc<Environment> {
( (
"hashmap", "hashmap",
Expression::NativeFunc(|args| { Expression::NativeFunc(|args| {
if args.len() % 2 != 0 { arg_count!(modulo: 2, args.len());
Err(Error::MismatchedArgCount(2, args.len()))?
}
let mut index = -1; let mut index = -1;
let (keys, values): (Vec<_>, Vec<_>) = args.into_iter().partition(|_| { let (keys, values): (Vec<_>, Vec<_>) = args.into_iter().partition(|_| {

View file

@ -5,6 +5,13 @@ macro_rules! arg_count {
Err(Error::MismatchedArgCount($expected, $given))? Err(Error::MismatchedArgCount($expected, $given))?
} }
}; };
(modulo: $modulo:expr, $given:expr) => {
Err(Error::MismatchedArgCount(
($given / $modulo) * $modulo + $modulo,
$given,
))?
};
} }
pub(crate) use arg_count; pub(crate) use arg_count;