Re: Generating recursive macros

From: Jeff (jma_at_nospam.insightbb.com)
Date: 08/15/04


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



Relevant Pages

  • Re: Putting evaluated constants in a CASE
    ... Jeff wrote: ... > could always fall back on COND or IF's, ... It quotes *X*, so your answer appears to be "no". ... the macro you want would be ten minutes' work. ...
    (comp.lang.lisp)
  • Putting evaluated constants in a CASE
    ... could always fall back on COND or IF's, ... if I'm missing a simple backquote operation or syntax construct, ... Jeff ...
    (comp.lang.lisp)
  • Re: Adding Rows and copying cells
    ... Jeff, I think Max is obviously right but I expect that wasn't the answer you ... ' InsertRow Macro ... Dim Response ... other sheets. ...
    (microsoft.public.excel.newusers)
  • Re: Change two hyphens to a dash
    ... Jeff McPherson ... >> your macro useful for, so I would love to have it. ... information about the em dash is lacking. ... I'm not sure about assigning Ctrl+- to the em dash as that is ...
    (microsoft.public.word.newusers)
  • Re: Calculating Difference In Time For Age
    ... I have the transfer text macro ... > just been starting with samll things, mostly using the macro first to get ... >> you're welcome, Jeff. ... >> i've worked extensively with automating data import/cleanup, ...
    (microsoft.public.access.reports)