[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem with macro definitions
From: |
hector |
Subject: |
Re: problem with macro definitions |
Date: |
Sat, 29 Apr 2017 18:06:32 +0200 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
Thank you for your reply.
On Sat, Apr 29, 2017 at 11:39:13AM +0200, Michael Heerdegen wrote:
> hector <hectorlahoz@gmail.com> writes:
>
> > I was looking for the complementary of nth, that is, a function that
> > returns the index of an element. Since it can be done at compilation
> > time
>
> Not if you want to use it on values that are known only at run-time.
I know. In this case when the list is constant it seemed to be right.
> > I thought it was a good candidate for a macro:
>
> No, not really:
>
> > (defmacro idx (list telt)
> > `(let (found
> > (idx 0))
> > (dolist (elt ,list found)
> > (when (eq elt ,telt)
> > (setq found idx))
> > (setq idx (1+ idx)))))
>
> You loose nothing when you rewrite this as a function. In this
> implementation, the index is calculated at run-time.
Let me rephrase your statement:
"You gain nothing when you write this as a macro. In this
implementation, the index is calculated at run-time"
I'm aware of that now. This is not what I meant.
I'll try to rewrite it.
> Note that macros don't evaluate their arguments. The argument 'blue you
> pass, a read syntax for (quote blue), is a list of two elements. This
> doesn't appear as an element of `start-states' which consists of four
> symbols.
This is the key to my confusion.