Page 1 of 1

Alternative "defun"

Posted: Fri Jul 01, 2011 5:38 am
by Indecipherable
I am trying to write a macro which works the same as defun - with name as "def"... Can anybody help? I think you can't write a function for this since you need to evaluate the name of the function, eg,

Code: Select all

(defmacro def (name parameters body) ?)
And the other problem is that there need to be multiple optional arguments and the body of the macro.
TIA

Re: Alternative "defun"

Posted: Fri Jul 01, 2011 6:06 am
by Konfusius
Usually defun is defined something like this:

Code: Select all

(defmacro def (name lambda-list &body body)
  (setf (symbol-function ',name)
        #'(lambda ,lambda-list ,@body)))

Re: Alternative "defun"

Posted: Fri Jul 01, 2011 7:10 am
by marcoxa