[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to put this in a macro
From: |
Barry Margolin |
Subject: |
Re: How to put this in a macro |
Date: |
Tue, 04 May 2010 15:45:03 -0000 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article
<bf0039f9-f7eb-497d-bb74-88d3bb9c5077@u34g2000yqu.googlegroups.com>,
José A. Romero L. <escherdragon@gmail.com> wrote:
> On 17 Kwi, 08:38, Cecil Westerhof <Ce...@decebal.nl> wrote:
> > Barry Margolin <bar...@alum.mit.edu> writes:
> > > (defmacro canonicalize-start-end (start-var end-var)
> > > `(if (equal ,start-var ,end-var)
> > > (setq ,start-var (point-min)
> > > ,end-var (point-max))
> > > (setq ,start-var (or ,start-var (point-min))
> > > ,end-var (or ,end-var (point-max))))
> >
> > This gives an error:
> > Debugger entered--Lisp error: (void-variable start-var)
> > (list (quote equal) start-var end-var)
> (...)
>
> Makes sense. In general writing things like `(setq ,foo bar) is (if
> possible at all) asking for trouble -- what would happen when foo is
> nil, or 5?
My macro requires that the parameters be variables, not expressions.
>
> Maybe you could do something like this:
>
> (defmacro cw/set-bounds (start-sym end-sym)
> `(if (equal (symbol-value ,start-sym) (symbol-value ,end-sym))
> (progn
> (set ,start-sym (point-min))
> (set ,end-sym (point-max)))
> (progn
> (set ,start-sym (or start (point-min)))
> (set ,end-sym (or end (point-max))))))
>
> and use it as:
>
> (cw/set-bounds 'start 'end)
>
> i.e. passing the symbols of the variables you want to set.
If you call it like that, it can be a function, not a macro.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
- Re: How to put this in a macro, (continued)
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Cecil Westerhof, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Cecil Westerhof, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Barry Margolin, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Barry Margolin, 2010/05/04
- Re: How to put this in a macro, Cecil Westerhof, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro,
Barry Margolin <=
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Barry Margolin, 2010/05/04
Re: How to put this in a macro, Pascal J. Bourguignon, 2010/05/04