Re: Generating recursive macros
From: Jeff (jma_at_nospam.insightbb.com)
Date: 08/15/04
- Next message: Abdulaziz Ghuloum: "Re: macros"
- Previous message: Matthew Danish: "Re: To diff or not to diff"
- In reply to: Jeff: "Re: Generating recursive macros"
- Next in thread: Matthew Danish: "Re: Generating recursive macros"
- Reply: Matthew Danish: "Re: Generating recursive macros"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 15 Aug 2004 00:27:27 GMT
Jeff wrote:
> Rainer Joswig wrote:
>
> > In article <1vxTc.153536$eM2.148253@attbi_s51>,
> > "Jeff" <jma@nospam.insightbb.com> wrote:
> >
> > > Wondering if someone could lend a quick hand with this one. I
> > > can't seem to get the correct code for the following concept:
> >
> > what concept?
> >
> > > (defmacro foo ()
> > > (let ((f (gensym)))
> > > `(labels ((,f () (,f)))))
> > >
> > > Of course, this isn't the macro I want, but the concept is there.
> > > I'd like to use a generated symbol for a label name so that I
> > > could call it recursively from within the label.
> > >
> > > I'm sure I'm just missing something simple. Help appreciated.
> > > Thanks!
> > >
> > > Jeff
> >
> > +1 parentheses:
> >
> > (defmacro foo ()
> > (let ((f (gensym)))
> > `(labels ((,f () (,f))))))
> >
> > Well, it will not do much if you call (foo).
> >
> > The following will be a loop...
> >
> > (defmacro foo ()
> > (let ((f (gensym)))
> > `(labels ((,f () (,f)))
> > (,f))))
>
> Hmm... there must be a little something wrong in my macro. I should
> have tested some more. I was getting the impression that a (gensym)
> couldn't be used in that way. Glad I was wrong :)
>
> Jeff
Ahh.. found it! Had to do with some gensym's being local in a cond
statement. Here is an example of what is generated:
(cond
((multiple-value-bind (m n) (...) m)
; Do stuff with m and n here
)
; more combinations of the same thing
)
So, of course, the section 'do stuff with m and n' will die because
they are out of scope. However, m and n are gensym'd before the cond
statement. Is there any way to force multiple-value-bind to use a
higher level symbol rather than creating new ones? Or perhaps get the
values of m and n withough using multiple-value-bind?
Thanks again for the replies, everyone.
Jeff
- Next message: Abdulaziz Ghuloum: "Re: macros"
- Previous message: Matthew Danish: "Re: To diff or not to diff"
- In reply to: Jeff: "Re: Generating recursive macros"
- Next in thread: Matthew Danish: "Re: Generating recursive macros"
- Reply: Matthew Danish: "Re: Generating recursive macros"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|