rxi / fe

A tiny, embeddable language implemented in ANSI C
MIT License
1.3k stars 81 forks source link

no-op in eval: P_FN/P_MAC #7

Closed prez closed 4 years ago

prez commented 4 years ago

In the P_FN and P_MAC case of eval, we set va to a newly allocated object containing (env . arg). Afterwards, we call fe_nextarg, discarding the return value and advancing the arg-list, which contains the argument list of the funtion and the expression itself. But the previous value of arg was already baked into va, and arg is not used anywhere later in eval (and is local to it).

Therefore, is the fe_nextarg line a no-op? https://github.com/rxi/fe/blob/master/src/fe.c#L660

Recompilation with the call removed does not seem to change the behaviour of function declaration.

rxi commented 4 years ago

The call to fe_nextarg is for checking for the existence of an argument to fn:

> (fn)
error: too few arguments

Without it the above code wouldn't cause an error and the resultant function would segfault when called.

prez commented 4 years ago

Thanks, that makes sense now - I haven't thought of this case. And sorry for the noise.