Reputation: 24750
So I can do this:
(defparameter *some-function* ... ; returns lambda later
or this:
(defun some-function ...
With either, I can use funcall
:
(funcall 'some-function ...
or
(funcall *some-function* ...
With the defun
version I can also do this:
(some-function ...
I cannot do that with the defparameter
function.
defparameter
provides easier technique for re-assigning some-function
to a different function (or anything else, including non-function data) later.
But other than these two points, what are other considerations of using one over another?
Upvotes: 6
Views: 320
Reputation: 3231
This is an odd one to answer as we are somewhat comparing apples with oranges.
For those new to lisp who are looking at this, defparameter is for defining a dynamic variable whereas defun is for defining a function.
If you are worried about being able to programmatically reassign a function without using defun check out the following:
CL-USER> (defun jam () (print 'some-jam))
JAM
CL-USER> (jam)
SOME-JAM
CL-USER> (setf (symbol-function 'jam) (lambda () (print 'some-ham)))
#<FUNCTION (LAMBDA ()) {1004C033DB}>
CL-USER> (jam)
SOME-HAM
So defparameter doesn’t have an advantage when it comes to reassigning a function. Also if you want to redefine the function you could look into the compile command.
Upvotes: 9