dmitry_vk wrote:Only the compiler knows how to call the function (because function is usually compiled to byte code or machine code), so it is not possible to write apply in CL.
I had a quick look at the SBCL source and found apply in
eval.lisp, line 279 - search for "defun apply".

Note however the comment just beforehand:
Code: Select all
276 ;;; miscellaneous full function definitions of things which are
277 ;;; ordinarily handled magically by the compiler
278
279 (defun apply (function arg &rest arguments)
280 #!+sb-doc
281 "Apply FUNCTION to a list of arguments produced by evaluating ARGUMENTS in
282 the manner of LIST*. That is, a list is made of the values of all but the
283 last argument, appended to the value of the last argument, which must be a
284 list."
285 (cond ((atom arguments)
286 (apply function arg))
287 ((atom (cdr arguments))
288 (apply function (cons arg (car arguments))))
289 (t (do* ((a1 arguments a2)
290 (a2 (cdr arguments) (cdr a2)))
291 ((atom (cdr a2))
292 (rplacd a1 (car a2))
293 (apply function (cons arg arguments)))))))
HTH!
[edit]
Although I don't understand how it can terminate

It seems to recurse in every case?
[edit2]
Or perhaps it's the "((atom (cdr a2)) (rplacd a1 (car a2))" end test.