From: His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated
Subject: Macro &BODY parser
Date: 
Message-ID: <w4oya91zuoo.fsf@nemesis.irtnog.org>
I wrote a parser that would take a &BODY argument and reduce it to a
DOCSTRING, a list of DECLARATIONS, and the BODY forms themselves.  I'm
not satisfied that it's the most efficient thing in the world, so if
anyone spots any glaring foolishness, please let me know.  As far as
I'm concerned, this code is hereby in the public domain.  I hope
somebody thinks it's useful

(defmacro ... (... &body body-form)
  (let (docstring declarations body)
    ;; parse BODY-FORM
    (let ((first-form (first body-form))
	  (second-form (second body-form))
	  (rest-of-forms (nthcdr 2 body-form)))
      (cond
       ;; ("docstring" (declare ...) ...)
       ((and (stringp first-form)
	     (consp second-form)
	     (eq (first second-form) 'declare))
	(setq docstring first-form)
	(setq declarations (cdr second-form))
	(setq body rest-of-forms))
       ;; ("docstring" ...)
       ((and (stringp first-form)
	     (not (and (consp second-form)
		       (eq (first second-form) 'declare))))
	(setq docstring first-form)
	(setq body (append (list second-form)
			   rest-of-forms)))
       ;; ((declare ...) "docstring" ...)
       ((and (consp first-form)
	     (eq (first first-form) 'declare)
	     (stringp second-form))
	(setq declarations (cdr first-form))
	(setq docstring second-form)
	(setq body rest-of-forms))
       ;; ((declare ...) ...)
       ((and (consp first-form)
	     (eq (first first-form) 'declare)
	     (not (stringp second-form)))
	(setq declarations (cdr first-form))
	(setq body (append (list second-form)
			   rest-of-forms)))
       ;; (...)
       (t
	(setq body (append (list first-form)
			   (list second-form)
			   rest-of-forms)))))
    ...))

-- 
Don't trust these UNIX people.  They are all demons.  They kill their
parents and fork children.  I don't know how they could do this with
their balls cut off but they manage.                        -- anonymous
From: Pierre R. Mai
Subject: Re: Macro &BODY parser
Date: 
Message-ID: <87k8kjv9of.fsf@orion.dent.isdn.cs.tu-berlin.de>
"His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated" <········@irtnog.org> writes:

> I wrote a parser that would take a &BODY argument and reduce it to a
> DOCSTRING, a list of DECLARATIONS, and the BODY forms themselves.  I'm
> not satisfied that it's the most efficient thing in the world, so if
> anyone spots any glaring foolishness, please let me know.  As far as
> I'm concerned, this code is hereby in the public domain.  I hope
> somebody thinks it's useful

You might want to look at the CMUCL source code, which includes a
couple of body parsers (for bodies of defuns, defmacros, etc.), to see 
how your approach compares...

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]