When do you use "apply" and when "funcall"?

Viewed 12464

The Common Lisp HyperSpec says in the funcall entry that

(funcall function arg1 arg2 ...) 
==  (apply function arg1 arg2 ... nil) 
==  (apply function (list arg1 arg2 ...))

Since they are somehow equivalent, when would you use apply, and when funcall?

4 Answers

Apply function is curring the result, like it returns a function that applies to next argument, to next argument. It is important subject on functional programming languages.

(mapcar 'list '((1 2)(3 4)))
(((1 2)) ((3 4)))

(funcall 'mapcar 'list '((1 2)(3 4)))
(((1 2)) ((3 4)))

(apply 'mapcar 'list '((1 2)(3 4)))
((1 3) (2 4))
Related