mirror of
https://github.com/samsonjs/lake.git
synced 2026-03-25 08:55:49 +00:00
consolidate arg checks in apply
This commit is contained in:
parent
4bfb171676
commit
e325a30b7b
1 changed files with 5 additions and 5 deletions
10
src/eval.c
10
src/eval.c
|
|
@ -346,10 +346,14 @@ LakeVal *apply(LakeCtx *ctx, LakeVal *fnVal, LakeList *args)
|
|||
|
||||
/* Check # of params */
|
||||
size_t nparams = LIST_N(fn->params);
|
||||
if (nparams != LIST_N(args) && !fn->varargs) {
|
||||
if (!fn->varargs && LIST_N(args) != nparams) {
|
||||
ERR("expected %zu params but got %zu", nparams, LIST_N(args));
|
||||
return NULL;
|
||||
}
|
||||
else if (fn->varargs && LIST_N(args) < nparams) {
|
||||
ERR("expected at least %zu params but got %zu", nparams, LIST_N(args));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Env *env = env_make(fn->closure);
|
||||
|
||||
|
|
@ -361,10 +365,6 @@ LakeVal *apply(LakeCtx *ctx, LakeVal *fnVal, LakeList *args)
|
|||
|
||||
/* bind varargs */
|
||||
if (fn->varargs) {
|
||||
if (LIST_N(args) < nparams) {
|
||||
ERR("expected at least %zu params but got %zu", nparams, LIST_N(args));
|
||||
return NULL;
|
||||
}
|
||||
LakeList *remainingArgs = list_make_with_capacity(LIST_N(args) - nparams);
|
||||
for (; i < LIST_N(args); ++i) {
|
||||
list_append(remainingArgs, LIST_VAL(args, i));
|
||||
|
|
|
|||
Loading…
Reference in a new issue