Alternative "defun"

Discussion of Common Lisp

Alternative "defun"

Postby 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 !
User avatar
Indecipherable
 
Posts: 47
Joined: Fri Jun 03, 2011 5:30 am
Location: Behind you.

Re: Alternative "defun"

Postby 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)))
Konfusius
 
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Alternative "defun"

Postby marcoxa » Fri Jul 01, 2011 7:10 am

Marco Antoniotti
marcoxa
 
Posts: 69
Joined: Thu Aug 14, 2008 6:31 pm


Return to Common Lisp

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests

cron