Alternative "defun"

Discussion of Common Lisp
Post Reply
Indecipherable
Posts: 47
Joined: Fri Jun 03, 2011 5:30 am
Location: Behind you.
Contact:

Alternative "defun"

Post by Indecipherable » Fri Jul 01, 2011 5:38 am

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
Don't take the FUN out of DEFUN !

Konfusius
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Alternative "defun"

Post by Konfusius » Fri Jul 01, 2011 6:06 am

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)))

marcoxa
Posts: 85
Joined: Thu Aug 14, 2008 6:31 pm

Re: Alternative "defun"

Post by marcoxa » Fri Jul 01, 2011 7:10 am

Marco Antoniotti

Post Reply