[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Example use of macro to minimize and generalize the code
From: |
Jean Louis |
Subject: |
Re: Example use of macro to minimize and generalize the code |
Date: |
Tue, 1 Jun 2021 20:24:31 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
* Yuri Khan <yuri.v.khan@gmail.com> [2021-06-01 20:12]:
> On Tue, 1 Jun 2021 at 23:38, Jean Louis <bugs@gnu.support> wrote:
>
> > > > (defmacro when-tabulated-id (table &rest body)
> > > > (declare (indent 2) (debug t))
> > > > ;;(ignore id)
> > > > `(if id
>
> > > Why don't you consider to make the id a real argument?
> >
> > I wish I could fully understand but I don't, and I consider your
> > advises important.
> >
> > How would I make the ID a real argument?
>
> I believe Michael is hinting at this:
>
> (defmacro when-tabulated-id (id table &rest body)
> `(if ,id
> …
>
> which means “at macro expansion time, substitute the value of the
> argument to the macro”, rather than your original
>
> (defmacro when-tabulated-id (id table &rest body)
> `(if id
> …
>
> which means “at evaluation time, substitute the value of the symbol
> 'id”.
I have removed `id' argument and now I have:
(macroexpand '(when-tabulated-id "people" (ignore)))
⇒ (if id (progn (ignore))
(if (or (eq "people" 'any) (string-equal "people" rcd-current-table))
(let ((id (tabulated-list-get-id)))
(if id (progn (ignore)) (message "Did not get ID")))
(message "This function is for table `%s' only" "people")))
If I would use ,d it would expand into number or nil, it seem it would end up
same.
Now I don't have compiler warnings, and functions work fine.
Let me know if I am making errors in this.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/