I think apply is typically supposed to take only 2
args:
arc> (apply + '((a b) ((c d) (e f))))
(a b (c d) (e f))
There's some special code that interprets apply with
3+ args differently. I don't know why apply with 3+
args is even allowed. Search ac.scm for ar-apply-args
and there's a comment about it. It seems to have
something to do with the arc/scheme boundary, but I
don't really understand the comment.
No, apply can take any number of args. The last arg is interpreted as a varargs parameter. This is in fact the entire reason 'apply exists at all, so it can expand the final list into individual args.
Not quite. All that the comment is talking about is that Arc lists are different from Scheme lists. In Arc, they end with the symbol 'nil (e.g., '(1 2 3) is the same as '(1 2 3 . nil)); in Scheme, they end with '() (e.g., '(1 2 3) is the same as '(1 2 3 . ())).
apply is perfectly well-defined for n arguments: (apply f x xs) is the same as (apply f (cons x xs)). In other words, if we think about apply as providing the contents of a list as arguments to a function, this is only relevant to the last argument. The rest are passed to the function normally. This is a nicety, allowing us to write things like (apply map + list-of-lists).