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.
Don't take the FUN out of DEFUN !
User avatar
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)))
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Alternative "defun"

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

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

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 5 guests