[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help defining desfstruct within non-top-level macro call

>From att!cs.sandia.gov!drstrip Mon Mar  5 14:20:11 MST 1990
>Received: by att.att.com; Tue Mar  6 00:51:07 1990
>Received: from Warbucks.AI.SRI.COM by IU.AI.SRI.COM via SMTP with TCP;
>  Mon, 5 Mar 90 13:23:09-PST
>Received: from ceratiidae.cs.sandia.gov by Warbucks.AI.SRI.COM with
>  INTERNET ; Mon, 5 Mar 90 13:18:35 PST
>Received: by ceratiidae.cs.sandia.gov (4.1/Exp-0.5) id AA12316; Mon,
>  5 Mar 90 14:20:11 MST
>Date: Mon, 5 Mar 90 14:20:11 MST
>From: drstrip@cs.sandia.gov (David R Strip (1411))
>Message-Id: <9003052120.AA12316@ceratiidae.cs.sandia.gov>
>To: slug@Warbucks.AI.SRI.COM
>Subject: Need help defining desfstruct within non-top-level macro call
>Status: O
>I am trying to write a macro that is called from within a function
>definition, but that includes the definition of a defstruct as a side
>effect of its expansion.
>First try is:
>(defmacro foo (struct-def) &body body
>	`(progn
>		(defstruct foo-struct ,@struct-def)
>		,@body))
>However, the macro is used within a defun:
>(defun bar (parm)
>	(mumble ...)
>	(foo (a b c)
>	     (something interesting)))
>which  expands into
>(defun bar (parm)
>	(mumble ...)
>	(progn
>	    (defstruct foo-struct a b c)
>	    (something interesting)))
>Now I really want the defstruct to be outside the defun.
>What I want to do is evaluate the defstruct part at compile and load
>time, not execution. But eval-when is only allowed at the top level. How
>do I move the defstruct to the appropriate place?

I really can't imagine why you'd want to do this... is there any reason
you can't have a DEFFOO at top-level which expands into the appropriate

However, I think you can do the following:
(DEFVAR *foo-structs* NIL)

(DEFMACRO Foo (slots &body body)
  (SETF *foo-structs*
     (CONS `(DEFSTRUCT Foo-Struct ,@slots) 
           (REMOVE 'foo-struct *foo-structs* :KEY #'SECOND)))
  `(PROGN ,@body))

and then place at the end of the file

(DEFMACRO All-Foo-Structs () `(PROGN ,@*foo-structs*))

David Loewenstern
AT&T Bell Laboratories
Whippany, NJ 07981
email: davel@whutt.att.com || whutt!davel
at&t: 201-386-6516